From c3346dd6cc9b6d90ed01e46db5c138fb10202c1b Mon Sep 17 00:00:00 2001 From: Marco Stornelli Date: Wed, 18 Mar 2020 16:19:39 +0100 Subject: Bug 561128 - Additional fix for lambda constexpr Change-Id: Ieee1eb4a494ec452bb5f710b2ffafd62ad798d2a --- .../tests/ast2/cxx14/constexpr/FunctionTests.java | 10 ++++++++++ .../cdt/internal/core/dom/parser/cpp/CPPFunction.java | 17 +++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'core') diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/constexpr/FunctionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/constexpr/FunctionTests.java index ed01e62a1b2..7a02be8d2b5 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/constexpr/FunctionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/cxx14/constexpr/FunctionTests.java @@ -281,4 +281,14 @@ public class FunctionTests extends TestBase { public void testLambdaExpression_560483() throws Exception { 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); + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 13baf5f1f81..391a4db7bb3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -777,17 +777,22 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt } public static ICPPExecution computeFunctionBodyExecution(IASTNode def) { - ICPPASTFunctionDefinition fnDef = getFunctionDefinition(def); - if (fnDef == null) { - ICPPASTLambdaExpression lambda = ASTQueries.findAncestorWithType(def, ICPPASTLambdaExpression.class); - if (lambda == null) - return null; + + while (def != null && !(def instanceof IASTDeclaration) && !(def instanceof ICPPASTLambdaExpression)) { + def = def.getParent(); + } + if (def == null) + return null; + + if (def instanceof ICPPASTLambdaExpression) { + ICPPASTLambdaExpression lambda = (ICPPASTLambdaExpression) def; ((ASTNode) lambda).resolvePendingAmbiguities(); if (lambda.getBody() instanceof CPPASTCompoundStatement) { CPPASTCompoundStatement body = (CPPASTCompoundStatement) lambda.getBody(); 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 // if it's a class method and we're still processing the class declaration. ((ASTNode) fnDef).resolvePendingAmbiguities(); -- cgit v1.2.3