1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 561128 - Additional fix for lambda constexpr

Change-Id: Ieee1eb4a494ec452bb5f710b2ffafd62ad798d2a
This commit is contained in:
Marco Stornelli 2020-03-18 16:19:39 +01:00 committed by Jonah Graham
parent a8b8573b8e
commit c3346dd6cc
2 changed files with 21 additions and 6 deletions

View file

@ -281,4 +281,14 @@ public class FunctionTests extends TestBase {
public void testLambdaExpression_560483() throws Exception { public void testLambdaExpression_560483() throws Exception {
assertEvaluationEquals(58); assertEvaluationEquals(58);
} }
// //Empty header file
// constexpr int f() {
// return ([]() constexpr -> int {return 58;})();
// }
// constexpr int x = f();
public void testLambdaExpression2_560483() throws Exception {
assertEvaluationEquals(58);
}
} }

View file

@ -777,17 +777,22 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
} }
public static ICPPExecution computeFunctionBodyExecution(IASTNode def) { public static ICPPExecution computeFunctionBodyExecution(IASTNode def) {
ICPPASTFunctionDefinition fnDef = getFunctionDefinition(def);
if (fnDef == null) { while (def != null && !(def instanceof IASTDeclaration) && !(def instanceof ICPPASTLambdaExpression)) {
ICPPASTLambdaExpression lambda = ASTQueries.findAncestorWithType(def, ICPPASTLambdaExpression.class); def = def.getParent();
if (lambda == null) }
return null; if (def == null)
return null;
if (def instanceof ICPPASTLambdaExpression) {
ICPPASTLambdaExpression lambda = (ICPPASTLambdaExpression) def;
((ASTNode) lambda).resolvePendingAmbiguities(); ((ASTNode) lambda).resolvePendingAmbiguities();
if (lambda.getBody() instanceof CPPASTCompoundStatement) { if (lambda.getBody() instanceof CPPASTCompoundStatement) {
CPPASTCompoundStatement body = (CPPASTCompoundStatement) lambda.getBody(); CPPASTCompoundStatement body = (CPPASTCompoundStatement) lambda.getBody();
return body.getExecution(); return body.getExecution();
} }
} else { } else if (def instanceof ICPPASTFunctionDefinition) {
ICPPASTFunctionDefinition fnDef = (ICPPASTFunctionDefinition) def;
// Make sure ambiguity resolution has been performed on the function body, even // Make sure ambiguity resolution has been performed on the function body, even
// if it's a class method and we're still processing the class declaration. // if it's a class method and we're still processing the class declaration.
((ASTNode) fnDef).resolvePendingAmbiguities(); ((ASTNode) fnDef).resolvePendingAmbiguities();