mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Bug 332285 - Parser misinterprets return statement in lambda
This commit is contained in:
parent
42958023ad
commit
b8b9084ce2
2 changed files with 27 additions and 15 deletions
|
@ -24,7 +24,7 @@ import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
|
||||||
|
@ -38,11 +38,11 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.c.ICASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLambdaExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
||||||
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The checker suppose to find issue related to mismatched return value/function
|
* The checker suppose to find issue related to mismatched return value/function
|
||||||
|
@ -65,6 +65,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
ReturnStmpVisitor(IASTFunctionDefinition func) {
|
ReturnStmpVisitor(IASTFunctionDefinition func) {
|
||||||
shouldVisitStatements = true;
|
shouldVisitStatements = true;
|
||||||
shouldVisitDeclarations = true;
|
shouldVisitDeclarations = true;
|
||||||
|
shouldVisitExpressions = true;
|
||||||
this.func = func;
|
this.func = func;
|
||||||
this.hasret = false;
|
this.hasret = false;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +75,12 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
return PROCESS_SKIP; // skip inner functions
|
return PROCESS_SKIP; // skip inner functions
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
public int visit(IASTExpression expr) {
|
||||||
|
if (expr instanceof ICPPASTLambdaExpression) {
|
||||||
|
return PROCESS_SKIP;
|
||||||
|
}
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
public int visit(IASTStatement stmt) {
|
public int visit(IASTStatement stmt) {
|
||||||
if (stmt instanceof IASTReturnStatement) {
|
if (stmt instanceof IASTReturnStatement) {
|
||||||
hasret = true;
|
hasret = true;
|
||||||
|
@ -94,14 +100,6 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
}
|
}
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
}
|
}
|
||||||
if (stmt instanceof IASTExpressionStatement) {
|
|
||||||
// do not process expression they may contain nasty stuff
|
|
||||||
IASTExpressionStatement stmt1 = (IASTExpressionStatement) stmt;
|
|
||||||
if (stmt1.getExpression() instanceof IGNUASTCompoundStatementExpression) {
|
|
||||||
return PROCESS_CONTINUE;
|
|
||||||
}
|
|
||||||
return PROCESS_SKIP;
|
|
||||||
}
|
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,14 @@ import org.eclipse.cdt.codan.internal.checkers.ReturnChecker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@see ReturnCheckerTest} class
|
* Test for {@see ReturnCheckerTest} class
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ReturnCheckerTest extends CheckerTestCase {
|
public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
|
@Override
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
enableProblems(ReturnChecker.RET_NORET_ID,ReturnChecker.RET_ERR_VALUE_ID,ReturnChecker.RET_NO_VALUE_ID);
|
||||||
|
}
|
||||||
// dummy() {
|
// dummy() {
|
||||||
// return; // error here on line 2
|
// return; // error here on line 2
|
||||||
// }
|
// }
|
||||||
|
@ -42,7 +47,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
// return; // error here on line 4
|
// return; // error here on line 4
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
public void testBasicTypeFunction() {
|
public void testBasicTypeFunction() {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkErrorLine(4);
|
checkErrorLine(4);
|
||||||
|
@ -62,7 +67,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// typedef unsigned int uint8_t;
|
// typedef unsigned int uint8_t;
|
||||||
//
|
//
|
||||||
// uint8_t return_typedef(void) {
|
// uint8_t return_typedef(void) {
|
||||||
// return; // error here on line 4
|
// return; // error here on line 4
|
||||||
// }
|
// }
|
||||||
|
@ -72,7 +77,7 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// typedef unsigned int uint8_t;
|
// typedef unsigned int uint8_t;
|
||||||
//
|
//
|
||||||
// uint8_t (*return_fp_no_typedef(void))(void)
|
// uint8_t (*return_fp_no_typedef(void))(void)
|
||||||
// {
|
// {
|
||||||
// return; // error here on line 5
|
// return; // error here on line 5
|
||||||
|
@ -146,6 +151,15 @@ public class ReturnCheckerTest extends CheckerTestCase {
|
||||||
loadCodeAndRunCpp(getAboveComment());
|
loadCodeAndRunCpp(getAboveComment());
|
||||||
checkNoErrors();
|
checkNoErrors();
|
||||||
}
|
}
|
||||||
|
// void f()
|
||||||
|
// {
|
||||||
|
// if ([](int r){return r == 0;}(0))
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
public void testLambda2_Bug332285() {
|
||||||
|
loadCodeAndRunCpp(getAboveComment());
|
||||||
|
checkNoErrors();
|
||||||
|
}
|
||||||
|
|
||||||
// void g()
|
// void g()
|
||||||
// {
|
// {
|
||||||
|
|
Loading…
Add table
Reference in a new issue