Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-04-21 06:17:39 -0400
committerNathan Ridge2019-04-21 13:46:24 -0400
commit3fcbb5c7b59b91713797f272ce5553783d748c70 (patch)
tree16c1de8900866459e5bea309a8cf0ab7870502e5
parent11a14b7ed3594b61559ed1b62e3080ff1fb04c72 (diff)
downloadorg.eclipse.cdt-3fcbb5c7b59b91713797f272ce5553783d748c70.tar.gz
org.eclipse.cdt-3fcbb5c7b59b91713797f272ce5553783d748c70.tar.xz
org.eclipse.cdt-3fcbb5c7b59b91713797f272ce5553783d748c70.zip
Bug 492878 - Fix no-return in function with goto
Change-Id: I39f2605aa2e5b697015a2dfdb795f163e76095cf Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java4
-rw-r--r--codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java12
2 files changed, 15 insertions, 1 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 e12ea7bbf8..da31be8f55 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
@@ -35,6 +35,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
+import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
@@ -210,7 +211,8 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
private boolean isCompoundStatement(IASTStatement last) {
return last instanceof IASTIfStatement || last instanceof IASTWhileStatement || last instanceof IASTDoStatement
|| last instanceof IASTForStatement || last instanceof IASTSwitchStatement
- || last instanceof IASTCompoundStatement || last instanceof ICPPASTTryBlockStatement;
+ || last instanceof IASTCompoundStatement || last instanceof ICPPASTTryBlockStatement
+ || last instanceof IASTGotoStatement;
}
protected boolean isFuncExitStatement(IASTStatement statement) {
diff --git a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
index 68290b6dfa..9e24f732d7 100644
--- a/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.tests/src/org/eclipse/cdt/codan/core/internal/checkers/ReturnCheckerTest.java
@@ -515,4 +515,16 @@ public class ReturnCheckerTest extends CheckerTestCase {
public void testTemplateFunctionNoReturn() throws Exception {
checkSampleAboveCpp();
}
+
+ //int foo() {
+ // int errcode = -1;
+ // errcode = 0;
+ // cleanup:
+ // return errcode;
+ // barf:
+ // goto cleanup;
+ //}
+ public void testNoReturnWithGoto_Bug492878() throws Exception {
+ checkSampleAboveCpp();
+ }
}

Back to the top