1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Revert "Bug 484959 - Instantiate return expression of constexpr function

template"

This reverts commit 1e598214ea.

Change-Id: I5fe7b602d3ecc26660f2bf8fe849ebbb5d6add3a
This commit is contained in:
Sergey Prigogin 2015-12-30 13:49:01 -08:00 committed by Gerrit Code Review @ Eclipse.org
parent 36d26c19e8
commit d8a72d1080
7 changed files with 8 additions and 68 deletions

View file

@ -8752,24 +8752,6 @@ public class AST2TemplateTests extends AST2TestBase {
public void testConstexprFunctionCallWithNonConstexprArguments_429891() throws Exception {
parseAndCheckBindings();
}
// template <typename>
// struct S;
//
// template <>
// struct S<int> {
// static const int value = 42;
// };
//
// template <typename T>
// constexpr int foo() {
// return S<T>::value;
// }
//
// constexpr int waldo = foo<int>();
public void testInstantiationOfReturnExpression_484959() throws Exception {
getAssertionHelper().assertVariableValue("waldo", 42);
}
// template <typename> class A {};
// template <int> class B {};

View file

@ -776,7 +776,9 @@ public class AST2TestBase extends BaseTestCase {
public void assertVariableValue(String variableName, long expectedValue) {
IVariable var = assertNonProblem(variableName);
BaseTestCase.assertVariableValue(var, expectedValue);
assertNotNull(var.getInitialValue());
assertNotNull(var.getInitialValue().numericalValue());
assertEquals(expectedValue, var.getInitialValue().numericalValue().longValue());
}
public <T, U extends T> U assertType(T obj, Class... cs) {

View file

@ -2644,25 +2644,6 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
public void testSpecializationOfConstexprFunction_420995() throws Exception {
checkBindings();
}
// template <typename>
// struct S;
//
// template <>
// struct S<int> {
// static const int value = 42;
// };
//
// template <typename T>
// constexpr int foo() {
// return S<T>::value;
// }
// constexpr int waldo = foo<int>();
public void testInstantiationOfReturnExpression_484959() throws Exception {
ICPPVariable waldo = getBindingFromASTName("waldo", 5);
assertVariableValue(waldo, 42);
}
// template <class TYPE>
// class waldo {

View file

@ -32,7 +32,6 @@ import junit.framework.TestResult;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent;
@ -350,10 +349,4 @@ public class BaseTestCase extends TestCase {
}
return clazz.cast(o);
}
protected static void assertVariableValue(IVariable var, long expectedValue) {
assertNotNull(var.getInitialValue());
assertNotNull(var.getInitialValue().numericalValue());
assertEquals(expectedValue, var.getInitialValue().numericalValue().longValue());
}
}

View file

@ -35,8 +35,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.internal.core.dom.parser.ASTInternal;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
import org.eclipse.cdt.internal.core.dom.parser.Value;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/**
@ -332,18 +330,7 @@ public class CPPFunctionSpecialization extends CPPSpecialization implements ICPP
}
IBinding f = getSpecializedBinding();
if (f instanceof ICPPComputableFunction) {
ICPPEvaluation eval = ((ICPPComputableFunction) f).getReturnExpression();
if (eval != null) {
// TODO: Should we instead do this when the CPPFunctionSpecialization is created?
// It would mean getting a more accurate point of instantiation, but it would also
// mean doing the instantiation when we might never need it.
IASTNode point = f instanceof ICPPInternalFunction
? ((ICPPInternalFunction) f).getDefinition()
: null;
eval = eval.instantiate(getTemplateParameterMap(), -1,
CPPTemplates.getSpecializationContext(getOwner()), Value.MAX_RECURSION_DEPTH, point);
}
return eval;
return ((ICPPComputableFunction) f).getReturnExpression();
}
return null;
}

View file

@ -39,6 +39,9 @@ public class CPPTemplateNonTypeArgument implements ICPPTemplateArgument {
IValue value = evaluation.getValue(point);
if (value == Value.ERROR) {
fEvaluation = EvalFixed.INCOMPLETE;
} else if (value.getEvaluation() instanceof EvalFixed) {
// Avoid nesting EvalFixed's as nesting causes the signature to be different.
fEvaluation = value.getEvaluation();
} else {
fEvaluation= new EvalFixed(evaluation.getType(point),
evaluation.getValueCategory(point), value);

View file

@ -45,14 +45,6 @@ public class EvalFixed extends CPPEvaluation {
private boolean fCheckedIsValueDependent;
public EvalFixed(IType type, ValueCategory cat, IValue value) {
// Avoid nesting EvalFixed's as nesting causes the signature to be different.
if (value.getEvaluation() instanceof EvalFixed) {
EvalFixed inner = (EvalFixed) value.getEvaluation();
type = inner.fType;
cat = inner.fValueCategory;
value = inner.fValue;
}
if (type instanceof CPPBasicType) {
Long num = value.numericalValue();
if (num != null) {
@ -65,7 +57,7 @@ public class EvalFixed extends CPPEvaluation {
fValueCategory= cat;
fValue= value;
}
public IType getType() {
return fType;
}