summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Wesolowski2011-06-26 14:34:05 (EDT)
committer Alena Laskavaia2011-06-26 14:34:05 (EDT)
commitc4ba6927fdba560eda04920c509fd33c9952d5fd (patch)
treee98cf5e2a185c3cf9cc5be6e7bfccb64647d52fa
parent617e4ddeda0b6dde643cb9026528e27cbdae0be4 (diff)
downloadorg.eclipse.cdt-c4ba6927fdba560eda04920c509fd33c9952d5fd.zip
org.eclipse.cdt-c4ba6927fdba560eda04920c509fd33c9952d5fd.tar.gz
org.eclipse.cdt-c4ba6927fdba560eda04920c509fd33c9952d5fd.tar.bz2
Bug 346559 - [fp] undeserved "no return in function returning non-void"
when using goto
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java5
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java15
2 files changed, 20 insertions, 0 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 548eae0..b917dec 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
@@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
+import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
@@ -150,6 +151,10 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
IASTStatement[] statements = ((IASTCompoundStatement) body).getStatements();
if (statements.length > 0) {
IASTStatement last = statements[statements.length - 1];
+ // get nested statement if this is a label
+ while (last instanceof IASTLabelStatement) {
+ last = ((IASTLabelStatement) last).getNestedStatement();
+ }
// now check if last statement if complex (for optimization reasons, building CFG is expensive)
if (isCompoundStatement(last)) {
if (endsWithNoExitNode(func))
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
index 9169ac6..b69f416 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
@@ -255,4 +255,19 @@ public class ReturnCheckerTest extends CheckerTestCase {
loadCodeAndRunCpp(getAboveComment());
checkErrorLine(1);
}
+
+ // int
+ // fp_goto(int a)
+ // {
+ // if (a) {
+ // goto end;
+ // }
+ // end:
+ // return (a);
+ // }
+ public void testGoto_Bug346559() {
+ loadCodeAndRun(getAboveComment());
+ checkNoErrors();
+ }
+
} \ No newline at end of file