mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Bug 420995 - Specializations of constexpr functions
Change-Id: I7e08e21eb62867d6bb42aa6904ab0fab472cb0bc Signed-off-by: Nathan Ridge <zeratul976@hotmail.com> Reviewed-on: https://git.eclipse.org/r/19936 Tested-by: Hudson CI Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com> IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com> Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
parent
227b03e6b8
commit
e0d1910ed4
13 changed files with 79 additions and 22 deletions
|
@ -8251,4 +8251,21 @@ public class AST2TemplateTests extends AST2TestBase {
|
|||
public void testStrayFriends_419301() throws Exception {
|
||||
parseAndCheckBindings();
|
||||
}
|
||||
|
||||
// template <typename T>
|
||||
// constexpr T t(T) {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// template <>
|
||||
// constexpr unsigned t<unsigned>(unsigned) {
|
||||
// return 1 + 1;
|
||||
// }
|
||||
//
|
||||
// constexpr unsigned waldo = t(0u);
|
||||
public void testSpecializationOfConstexprFunction_420995() throws Exception {
|
||||
BindingAssertionHelper helper = getAssertionHelper();
|
||||
ICPPVariable waldo = helper.assertNonProblem("waldo");
|
||||
assertEquals(2, waldo.getInitialValue().numericalValue().longValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2454,4 +2454,19 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
|
|||
public void testFriendFunctionOfClassSpecialization_419301b() throws Exception {
|
||||
checkBindings();
|
||||
}
|
||||
|
||||
// template <typename T>
|
||||
// constexpr T t(T) {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// template <>
|
||||
// constexpr unsigned t<unsigned>(unsigned) {
|
||||
// return 1 + 1;
|
||||
// }
|
||||
|
||||
// // empty source file
|
||||
public void testSpecializationOfConstexprFunction_420995() throws Exception {
|
||||
checkBindings();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -422,7 +422,7 @@ public class Value implements IValue {
|
|||
|
||||
if (expr instanceof ICPPASTInitializerClause) {
|
||||
ICPPEvaluation evaluation = ((ICPPASTInitializerClause) expr).getEvaluation();
|
||||
return new Value(null, evaluation);
|
||||
return evaluation.getValue(expr);
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
|
|
@ -35,8 +35,14 @@ public class CPPTemplateNonTypeArgument implements ICPPTemplateArgument {
|
|||
evaluation.isTypeDependent() || evaluation.isValueDependent()) {
|
||||
fEvaluation= evaluation;
|
||||
} else {
|
||||
fEvaluation= new EvalFixed(evaluation.getTypeOrFunctionSet(point),
|
||||
evaluation.getValueCategory(point), evaluation.getValue(point));
|
||||
IValue value = evaluation.getValue(point);
|
||||
// Avoid nesting EvalFixed's as nesting causes the signature to be different.
|
||||
if (value.getEvaluation() instanceof EvalFixed) {
|
||||
fEvaluation = value.getEvaluation();
|
||||
} else {
|
||||
fEvaluation= new EvalFixed(evaluation.getTypeOrFunctionSet(point),
|
||||
evaluation.getValueCategory(point), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
|
||||
|
||||
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeFromReturnType;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromFunctionCall;
|
||||
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCategoryFromReturnType;
|
||||
|
@ -149,12 +148,10 @@ public class EvalFunctionCall extends CPPDependentEvaluation {
|
|||
@Override
|
||||
public IValue getValue(IASTNode point) {
|
||||
ICPPEvaluation eval = computeForFunctionCall(Value.MAX_RECURSION_DEPTH, point);
|
||||
if (eval != this) {
|
||||
if (eval instanceof EvalFixed)
|
||||
return ((EvalFixed) eval).getValue();
|
||||
eval = new EvalFixed(getTypeOrFunctionSet(point), PRVALUE, eval.getValue(point));
|
||||
}
|
||||
return Value.create(eval);
|
||||
if (eval == this) {
|
||||
return Value.create(eval);
|
||||
}
|
||||
return eval.getValue(point);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,7 +28,7 @@ public class PDOMCPPConstructorInstance extends PDOMCPPMethodInstance implements
|
|||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMCPPMethodInstance.RECORD_SIZE + 0;
|
||||
|
||||
public PDOMCPPConstructorInstance(PDOMLinkage linkage, PDOMNode parent, ICPPMethod method,
|
||||
public PDOMCPPConstructorInstance(PDOMCPPLinkage linkage, PDOMNode parent, ICPPMethod method,
|
||||
PDOMBinding instantiated) throws CoreException {
|
||||
super(linkage, parent, method, instantiated);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class PDOMCPPConstructorSpecialization extends PDOMCPPMethodSpecialization imple
|
|||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMCPPMethodSpecialization.RECORD_SIZE + 0;
|
||||
|
||||
public PDOMCPPConstructorSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPConstructor constructor, PDOMBinding specialized) throws CoreException {
|
||||
public PDOMCPPConstructorSpecialization(PDOMCPPLinkage linkage, PDOMNode parent, ICPPConstructor constructor, PDOMBinding specialized) throws CoreException {
|
||||
super(linkage, parent, constructor, specialized);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class PDOMCPPFunctionInstance extends PDOMCPPFunctionSpecialization implements I
|
|||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMCPPFunctionSpecialization.RECORD_SIZE + 8;
|
||||
|
||||
public PDOMCPPFunctionInstance(PDOMLinkage linkage, PDOMNode parent, ICPPFunction function, PDOMBinding orig)
|
||||
public PDOMCPPFunctionInstance(PDOMCPPLinkage linkage, PDOMNode parent, ICPPFunction function, PDOMBinding orig)
|
||||
throws CoreException {
|
||||
super(linkage, parent, function, orig);
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPComputableFunction;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
|
||||
|
@ -84,7 +83,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
|
|||
private short fAnnotation= -1;
|
||||
private int fRequiredArgCount= -1;
|
||||
|
||||
public PDOMCPPFunctionSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPFunction astFunction,
|
||||
public PDOMCPPFunctionSpecialization(PDOMCPPLinkage linkage, PDOMNode parent, ICPPFunction astFunction,
|
||||
PDOMBinding specialized) throws CoreException {
|
||||
super(linkage, parent, (ICPPSpecialization) astFunction, specialized);
|
||||
|
||||
|
@ -123,10 +122,6 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
|
|||
fAnnotation = getAnnotation(astFunction);
|
||||
db.putShort(record + ANNOTATION, fAnnotation);
|
||||
db.putShort(record + REQUIRED_ARG_COUNT , (short) astFunction.getRequiredArgumentCount());
|
||||
ICPPEvaluation returnExpression = CPPFunction.getReturnExpression(astFunction);
|
||||
if (returnExpression != null) {
|
||||
linkage.storeEvaluation(record + RETURN_EXPRESSION, returnExpression);
|
||||
}
|
||||
long typelist= 0;
|
||||
if (astFunction instanceof ICPPMethod && ((ICPPMethod) astFunction).isImplicit()) {
|
||||
// Don't store the exception specification, it is computed on demand.
|
||||
|
@ -134,6 +129,7 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
|
|||
typelist = PDOMCPPTypeList.putTypes(this, astFunction.getExceptionSpecification());
|
||||
}
|
||||
db.putRecPtr(record + EXCEPTION_SPEC, typelist);
|
||||
linkage.new ConfigureFunctionSpecialization(astFunction, this);
|
||||
}
|
||||
|
||||
private short getAnnotation(ICPPFunction astFunction) {
|
||||
|
@ -154,6 +150,16 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization
|
|||
super(linkage, bindingRecord);
|
||||
}
|
||||
|
||||
public void initData(ICPPEvaluation returnExpression) {
|
||||
if (returnExpression == null)
|
||||
return;
|
||||
try {
|
||||
getLinkage().storeEvaluation(record + RETURN_EXPRESSION, returnExpression);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRecordSize() {
|
||||
return RECORD_SIZE;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
class PDOMCPPFunctionTemplateSpecialization extends PDOMCPPFunctionSpecialization
|
||||
implements ICPPFunctionTemplate, ICPPInstanceCache, IPDOMMemberOwner {
|
||||
|
||||
public PDOMCPPFunctionTemplateSpecialization(PDOMLinkage linkage, PDOMNode parent,
|
||||
public PDOMCPPFunctionTemplateSpecialization(PDOMCPPLinkage linkage, PDOMNode parent,
|
||||
ICPPFunctionTemplate template, PDOMBinding specialized) throws CoreException {
|
||||
super(linkage, parent, template, specialized);
|
||||
}
|
||||
|
|
|
@ -251,6 +251,22 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
fReturnExpression);
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigureFunctionSpecialization implements Runnable {
|
||||
private final PDOMCPPFunctionSpecialization fSpec;
|
||||
private final ICPPEvaluation fReturnExpression;
|
||||
|
||||
public ConfigureFunctionSpecialization(ICPPFunction original, PDOMCPPFunctionSpecialization spec) {
|
||||
fSpec = spec;
|
||||
fReturnExpression = CPPFunction.getReturnExpression(original);
|
||||
postProcesses.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
fSpec.initData(fReturnExpression);
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigureFunctionTemplate implements Runnable {
|
||||
private final PDOMCPPFunctionTemplate fTemplate;
|
||||
|
|
|
@ -30,7 +30,7 @@ class PDOMCPPMethodInstance extends PDOMCPPFunctionInstance implements ICPPMetho
|
|||
@SuppressWarnings("hiding")
|
||||
protected static final int RECORD_SIZE = PDOMCPPFunctionInstance.RECORD_SIZE + 0;
|
||||
|
||||
public PDOMCPPMethodInstance(PDOMLinkage linkage, PDOMNode parent, ICPPMethod method, PDOMBinding instantiated)
|
||||
public PDOMCPPMethodInstance(PDOMCPPLinkage linkage, PDOMNode parent, ICPPMethod method, PDOMBinding instantiated)
|
||||
throws CoreException {
|
||||
super(linkage, parent, method, instantiated);
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class PDOMCPPMethodSpecialization extends PDOMCPPFunctionSpecialization
|
|||
*/
|
||||
private static final int CV_OFFSET = PDOMCPPAnnotation.MAX_EXTRA_OFFSET + 1;
|
||||
|
||||
public PDOMCPPMethodSpecialization(PDOMLinkage linkage, PDOMNode parent, ICPPMethod method, PDOMBinding specialized) throws CoreException {
|
||||
public PDOMCPPMethodSpecialization(PDOMCPPLinkage linkage, PDOMNode parent, ICPPMethod method, PDOMBinding specialized) throws CoreException {
|
||||
super(linkage, parent, method, specialized);
|
||||
Database db = getDB();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue