summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Wesolowski2011-06-25 22:29:01 (EDT)
committerAlena Laskavaia2011-06-25 22:29:01 (EDT)
commit0060fff70212821ed51e7c13d9ed33a5e2254943 (patch)
tree80c0f635f265a605eb2ddfc6477492e2e84682a5
parent30a6e551f5d7c355da1e834750109c89ecc1e293 (diff)
downloadorg.eclipse.cdt-0060fff70212821ed51e7c13d9ed33a5e2254943.zip
org.eclipse.cdt-0060fff70212821ed51e7c13d9ed33a5e2254943.tar.gz
org.eclipse.cdt-0060fff70212821ed51e7c13d9ed33a5e2254943.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