diff options
author | Alena Laskavaia | 2010-08-27 00:47:28 +0000 |
---|---|---|
committer | Alena Laskavaia | 2010-08-27 00:47:28 +0000 |
commit | da074afa86e08b9ea953e14def164ab612c043e2 (patch) | |
tree | fef232143b2d69852f9f6d98dbabd1317a380f50 /codan/org.eclipse.cdt.codan.checkers | |
parent | 54aeb3242fd0b4ae36efdd236080328a59518ae4 (diff) | |
download | org.eclipse.cdt-da074afa86e08b9ea953e14def164ab612c043e2.tar.gz org.eclipse.cdt-da074afa86e08b9ea953e14def164ab612c043e2.tar.xz org.eclipse.cdt-da074afa86e08b9ea953e14def164ab612c043e2.zip |
Bug 323602: fixed f.p. in constructors/destructors for return checker
Diffstat (limited to 'codan/org.eclipse.cdt.codan.checkers')
-rw-r--r-- | codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java index 77e963f73b4..3ebc6131945 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java @@ -34,6 +34,9 @@ import org.eclipse.cdt.core.dom.ast.IBasicType; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; /** * The checker suppose to find issue related to mismatched return value/function @@ -44,10 +47,10 @@ import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier; * flow graph) */ public class ReturnChecker extends AbstractAstFunctionChecker { - private static final String PARAM_IMPLICIT = "implicit"; //$NON-NLS-1$ - public final String RET_NO_VALUE_ID = "org.eclipse.cdt.codan.checkers.noreturn"; //$NON-NLS-1$ - public final String RET_ERR_VALUE_ID = "org.eclipse.cdt.codan.checkers.errreturnvalue"; //$NON-NLS-1$ - public final String RET_NORET_ID = "org.eclipse.cdt.codan.checkers.errnoreturn"; //$NON-NLS-1$ + public static final String PARAM_IMPLICIT = "implicit"; //$NON-NLS-1$ + public static final String RET_NO_VALUE_ID = "org.eclipse.cdt.codan.checkers.noreturn"; //$NON-NLS-1$ + public static final String RET_ERR_VALUE_ID = "org.eclipse.cdt.codan.checkers.errreturnvalue"; //$NON-NLS-1$ + public static final String RET_NORET_ID = "org.eclipse.cdt.codan.checkers.errnoreturn"; //$NON-NLS-1$ class ReturnStmpVisitor extends ASTVisitor { private IASTFunctionDefinition func; @@ -68,9 +71,10 @@ public class ReturnChecker extends AbstractAstFunctionChecker { if (stmt instanceof IASTReturnStatement) { hasret = true; IASTReturnStatement ret = (IASTReturnStatement) stmt; - if (!isVoid(func)) { + if (!isVoid(func) && !isConstructorDestructor()) { if (checkImplicitReturn(RET_NO_VALUE_ID) || isExplicitReturn(func)) { + if (ret.getReturnValue() == null) reportProblem(RET_NO_VALUE_ID, ret); } @@ -87,6 +91,19 @@ public class ReturnChecker extends AbstractAstFunctionChecker { } return PROCESS_CONTINUE; } + /** + * @return + * + */ + public boolean isConstructorDestructor() { + if (func instanceof ICPPASTFunctionDefinition) { + IBinding method = func.getDeclarator().getName().resolveBinding(); + if (method instanceof ICPPConstructor || method instanceof ICPPMethod && ((ICPPMethod)method).isDestructor()) { + return true; + } + } + return false; + } } |