mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 346559 - [fp] undeserved "no return in function returning non-void"
when using goto
This commit is contained in:
parent
617e4ddeda
commit
c4ba6927fd
2 changed files with 20 additions and 0 deletions
|
@ -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))
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue