Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlena Laskavaia2011-06-27 22:01:24 -0400
committerAlena Laskavaia2011-06-27 22:04:01 -0400
commit5431dae21921e1d3773335c1b36e120209dadfd2 (patch)
tree4cb9a86b0ad89c326582d138b731ddfb3fa44b56 /codan/org.eclipse.cdt.codan.checkers
parent6b80326e1789315fc94f20aedf3e38b67f218a89 (diff)
downloadorg.eclipse.cdt-5431dae21921e1d3773335c1b36e120209dadfd2.tar.gz
org.eclipse.cdt-5431dae21921e1d3773335c1b36e120209dadfd2.tar.xz
org.eclipse.cdt-5431dae21921e1d3773335c1b36e120209dadfd2.zip
Bug 332283 - Parser gives warning if main does not return anything
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.java17
1 files changed, 14 insertions, 3 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 86a9d9e25a..f7bc5fca93 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
@@ -131,6 +131,18 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
return false;
}
+ public boolean isMain(IASTFunctionDefinition func) {
+ try {
+ String functionName = func.getDeclarator().getName().getRawSignature();
+ if (functionName.equals("main")) { //$NON-NLS-1$
+ return true;
+ }
+ } catch (Exception e) {
+ // well, not main
+ }
+ return false;
+ }
+
/*
* (non-Javadoc)
*
@@ -144,7 +156,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
ReturnStmpVisitor visitor = new ReturnStmpVisitor(func);
func.accept(visitor);
boolean nonVoid = !isVoid(func);
- if (nonVoid) {
+ if (nonVoid && !isMain(func)) {
// there a return but maybe it is only on one branch
IASTStatement body = func.getBody();
if (body instanceof IASTCompoundStatement) {
@@ -163,8 +175,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
reportNoRet(func, visitor.hasret);
}
} else {
-
- reportNoRet(func, false);
+ reportNoRet(func, false);
}
}
}

Back to the top