Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorSergey Prigogin2016-10-05 01:49:52 +0000
committerSergey Prigogin2016-10-05 01:49:52 +0000
commited0b384e9d39e229d98174081383c262c75dd79e (patch)
treeffc6420bcc3e2203eea2468801db7ff17a7ca053 /codan
parent2a3a9d6b4badabd29ed359cbb98be7027e281c66 (diff)
downloadorg.eclipse.cdt-ed0b384e9d39e229d98174081383c262c75dd79e.tar.gz
org.eclipse.cdt-ed0b384e9d39e229d98174081383c262c75dd79e.tar.xz
org.eclipse.cdt-ed0b384e9d39e229d98174081383c262c75dd79e.zip
Bug 504004 - ReturnChecker should treat constructors and destructors as
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java28
1 files changed, 16 insertions, 12 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 786ccff9505..8b23febac16 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
@@ -106,7 +106,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
if (returnValue != null) {
hasret = true;
}
- if (!isVoid(func) && !isConstructorDestructor(func)) {
+ if (isNonVoid(func) && !isConstructorDestructor(func)) {
if (checkImplicitReturn(RET_NO_VALUE_ID) || isExplicitReturn(func)) {
if (returnValue == null)
reportProblem(RET_NO_VALUE_ID, ret);
@@ -153,7 +153,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
return; // If it is template get out of here.
ReturnStmpVisitor visitor = new ReturnStmpVisitor(func);
func.accept(visitor);
- boolean nonVoid = !isVoid(func);
+ boolean nonVoid = isNonVoid(func);
if (nonVoid && !isMain(func)) {
// There a return but maybe it is only on one branch.
IASTStatement body = func.getBody();
@@ -201,9 +201,6 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
if (!checkImplicitReturn(RET_NORET_ID) && !isExplicitReturn(func)) {
return;
}
- if (isConstructorDestructor(func)) {
- return;
- }
}
reportProblem(RET_NORET_ID, func.getDeclSpecifier());
@@ -251,18 +248,25 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
return getDeclSpecType(func) != IASTSimpleDeclSpecifier.t_unspecified;
}
- public boolean isVoid(IASTFunctionDefinition func) {
+ /**
+ * Checks if the function has a return type other than void. Constructors and destructors
+ * don't have return type.
+ *
+ * @param func the function to check
+ * @return {@code true} if the function has a non void return type
+ */
+ private boolean isNonVoid(IASTFunctionDefinition func) {
+ if (isConstructorDestructor(func))
+ return false;
int type = getDeclSpecType(func);
if (type == IASTSimpleDeclSpecifier.t_void) {
IASTFunctionDeclarator declarator = func.getDeclarator();
if (declarator.getPointerOperators().length == 0)
- return true;
- } else if (type == IASTSimpleDeclSpecifier.t_auto) {
- if (isAutoVoid(func)) {
- return true;
- }
+ return false;
+ } else if (type == IASTSimpleDeclSpecifier.t_auto && isAutoVoid(func)) {
+ return false;
}
- return false;
+ return true;
}
/**

Back to the top