diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index 14143b55929..62824df8837 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -2375,9 +2375,9 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // B::type x; // B::type y; public void testConstexprFunction_395238_2() throws Exception { - ITypedef td = getBindingFromASTName("type x", 4, ITypedef.class); + ITypedef td = getBindingFromFirstIdentifier("type x", ITypedef.class); assertEquals("bool", ASTTypeUtil.getType(td.getType())); - getProblemFromASTName("type y", 4); + getProblemFromFirstIdentifier("type y"); } // template @@ -2536,6 +2536,51 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa checkBindings(); } + // // Empty header. + + // template + // constexpr T a() { return v; } + // + // template + // constexpr T A(T n, int i, T j = 1) { + // return (i < 1) ? j : (i == 1) ? n * j : A(n * n, i / 2, (i % 2) ? j * n : j); + // } + // + // template + // struct B { + // static constexpr int b(T n); + // }; + // + // template + // struct B { + // static constexpr int b(T n) { + // return J; + // } + // }; + // + // template + // constexpr int B::b(T n) { + // return (n < a(I, (J + K) / 2)>()) ? + // B::b(n) : + // B::b(n); + // } + // + // template + // constexpr int C(T v = 2000000000) { + // return v < I ? 1 : 1 + C(v / I); + // } + // + // template + // constexpr int D(T n) { + // return B(), T>::b(n); + // } + // + // static_assert(D<10>(1000000000) == 10, ""); + public void testOOM_497875() throws Exception { + // TODO(sprigogin): Uncomment after http://bugs.eclipse.org/497931 is fixed. +// checkBindings(); + } + // template // struct basic_A { // bool eof() const; @@ -2664,7 +2709,7 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa // constexpr int waldo = foo(); public void testInstantiationOfReturnExpression_484959() throws Exception { - ICPPVariable waldo = getBindingFromASTName("waldo", 5); + ICPPVariable waldo = getBindingFromFirstIdentifier("waldo"); assertVariableValue(waldo, 42); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java index 62d03d363e2..b9daf5ea65a 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalFunctionCall.java @@ -30,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.IValue; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap; import org.eclipse.cdt.internal.core.dom.parser.ISerializableEvaluation; import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer; @@ -242,9 +243,24 @@ public class EvalFunctionCall extends CPPDependentEvaluation { } if (function == null) return this; + ICPPEvaluation eval = CPPFunction.getReturnExpression(function, context.getPoint()); - if (eval == null) - return EvalFixed.INCOMPLETE; + if (eval == null) { + if (!(function instanceof ICPPTemplateInstance) + || ((ICPPTemplateInstance) function).isExplicitSpecialization()) { + return EvalFixed.INCOMPLETE; + } + ICPPTemplateInstance functionInstance = (ICPPTemplateInstance) function; + IBinding specialized = functionInstance.getSpecializedBinding(); + if (!(specialized instanceof ICPPFunction)) + return this; + eval = CPPFunction.getReturnExpression((ICPPFunction) specialized, context.getPoint()); + if (eval == null) + return EvalFixed.INCOMPLETE; + InstantiationContext instantiationContext = + new InstantiationContext(functionInstance.getTemplateParameterMap(), context.getPoint()); + return eval.instantiate(instantiationContext, Value.MAX_RECURSION_DEPTH); + } CPPFunctionParameterMap parameterMap = buildParameterMap(function, context.getPoint()); return eval.computeForFunctionCall(parameterMap, context.recordStep()); } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java index 158cde7f9b5..41e5a2ebd75 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/cpp/PDOMCPPFunctionSpecialization.java @@ -23,6 +23,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType; 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.core.dom.ast.cpp.ICPPTemplateInstance; import org.eclipse.cdt.internal.core.dom.parser.ProblemFunctionType; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPComputableFunction; import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPEvaluation; @@ -130,7 +131,10 @@ class PDOMCPPFunctionSpecialization extends PDOMCPPSpecialization typelist = PDOMCPPTypeList.putTypes(this, astFunction.getExceptionSpecification()); } db.putRecPtr(record + EXCEPTION_SPEC, typelist); - linkage.new ConfigureFunctionSpecialization(astFunction, this, point); + if (!(astFunction instanceof ICPPTemplateInstance) + || ((ICPPTemplateInstance) astFunction).isExplicitSpecialization()) { + linkage.new ConfigureFunctionSpecialization(astFunction, this, point); + } } private short getAnnotation(ICPPFunction astFunction) {