mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Bug 561128 - Add constexpr evaluation for lambda expressions
Change-Id: I28916218c7d2326407b28170ac051c18ec501f49
This commit is contained in:
parent
f150522ad4
commit
16d73e0081
3 changed files with 31 additions and 7 deletions
|
@ -274,4 +274,11 @@ public class FunctionTests extends TestBase {
|
||||||
// .m(21).m(22).m(23).m(24).m(25).m(26).m(27).m(28).m(29).m(30);
|
// .m(21).m(22).m(23).m(24).m(25).m(26).m(27).m(28).m(29).m(30);
|
||||||
public void testLongCallChain_505606() throws Exception {
|
public void testLongCallChain_505606() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// auto f = []() constexpr -> int {return 58;};
|
||||||
|
|
||||||
|
// constexpr int x = f();
|
||||||
|
public void testLambdaExpression_560483() throws Exception {
|
||||||
|
assertEvaluationEquals(58);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -103,7 +103,7 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP
|
||||||
// Deleted copy assignment operator: A& operator = (const A &)
|
// Deleted copy assignment operator: A& operator = (const A &)
|
||||||
IType refType = new CPPReferenceType(this, false);
|
IType refType = new CPPReferenceType(this, false);
|
||||||
ICPPFunctionType ft = CPPVisitor.createImplicitFunctionType(refType, ps, false, false);
|
ICPPFunctionType ft = CPPVisitor.createImplicitFunctionType(refType, ps, false, false);
|
||||||
ICPPMethod m = new CPPImplicitMethod(scope, OverloadableOperator.ASSIGN.toCharArray(), ft, ps, false);
|
CPPImplicitMethod m = new CPPImplicitMethod(scope, OverloadableOperator.ASSIGN.toCharArray(), ft, ps, false);
|
||||||
result[2] = m;
|
result[2] = m;
|
||||||
|
|
||||||
// Destructor: ~A()
|
// Destructor: ~A()
|
||||||
|
@ -120,22 +120,28 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP
|
||||||
|
|
||||||
ICPPParameter[] params = getParameters();
|
ICPPParameter[] params = getParameters();
|
||||||
char[] operatorParensName = OverloadableOperator.PAREN.toCharArray();
|
char[] operatorParensName = OverloadableOperator.PAREN.toCharArray();
|
||||||
|
ICPPASTFunctionDeclarator dtor = fLambdaExpression.getDeclarator();
|
||||||
|
boolean constExpr = false;
|
||||||
|
if (dtor != null) {
|
||||||
|
constExpr = dtor.isConstexpr();
|
||||||
|
}
|
||||||
if (isGeneric()) {
|
if (isGeneric()) {
|
||||||
m = new CPPImplicitMethodTemplate(getInventedTemplateParameterList(), scope, operatorParensName, ft, params,
|
m = new CPPImplicitMethodTemplate(getInventedTemplateParameterList(), scope, operatorParensName, ft, params,
|
||||||
false) {
|
constExpr) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isImplicit() {
|
public boolean isImplicit() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
m = new CPPImplicitMethod(scope, operatorParensName, ft, params, false) {
|
m = new CPPImplicitMethod(scope, operatorParensName, ft, params, constExpr) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isImplicit() {
|
public boolean isImplicit() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
m.addDefinition(fLambdaExpression.getDeclarator());
|
||||||
result[4] = m;
|
result[4] = m;
|
||||||
|
|
||||||
// Conversion operator
|
// Conversion operator
|
||||||
|
@ -156,14 +162,14 @@ public class CPPClosureType extends PlatformObject implements ICPPClassType, ICP
|
||||||
templateParamClones[i] = (ICPPTemplateParameter) ((IType) templateParams[i]).clone();
|
templateParamClones[i] = (ICPPTemplateParameter) ((IType) templateParams[i]).clone();
|
||||||
}
|
}
|
||||||
m = new CPPImplicitMethodTemplate(templateParamClones, scope, conversionOperatorName, ft, params,
|
m = new CPPImplicitMethodTemplate(templateParamClones, scope, conversionOperatorName, ft, params,
|
||||||
false) {
|
constExpr) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isImplicit() {
|
public boolean isImplicit() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
m = new CPPImplicitMethod(scope, conversionOperatorName, ft, params, false) {
|
m = new CPPImplicitMethod(scope, conversionOperatorName, ft, params, constExpr) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isImplicit() {
|
public boolean isImplicit() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -41,6 +41,7 @@ import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTDeclSpecifier;
|
||||||
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.ICPPASTParameterDeclaration;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
|
||||||
|
@ -625,8 +626,9 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
||||||
@Override
|
@Override
|
||||||
public boolean isConstexpr() {
|
public boolean isConstexpr() {
|
||||||
ICPPASTDeclSpecifier declSpec = getDeclSpecifier();
|
ICPPASTDeclSpecifier declSpec = getDeclSpecifier();
|
||||||
if (declSpec == null)
|
if (declSpec == null) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return declSpec.isConstexpr();
|
return declSpec.isConstexpr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,7 +778,16 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
|
||||||
|
|
||||||
public static ICPPExecution computeFunctionBodyExecution(IASTNode def) {
|
public static ICPPExecution computeFunctionBodyExecution(IASTNode def) {
|
||||||
ICPPASTFunctionDefinition fnDef = getFunctionDefinition(def);
|
ICPPASTFunctionDefinition fnDef = getFunctionDefinition(def);
|
||||||
if (fnDef != null) {
|
if (fnDef == null) {
|
||||||
|
ICPPASTLambdaExpression lambda = ASTQueries.findAncestorWithType(def, ICPPASTLambdaExpression.class);
|
||||||
|
if (lambda == null)
|
||||||
|
return null;
|
||||||
|
((ASTNode) lambda).resolvePendingAmbiguities();
|
||||||
|
if (lambda.getBody() instanceof CPPASTCompoundStatement) {
|
||||||
|
CPPASTCompoundStatement body = (CPPASTCompoundStatement) lambda.getBody();
|
||||||
|
return body.getExecution();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// 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();
|
||||||
|
|
Loading…
Add table
Reference in a new issue