Skip to content

Commit

Permalink
[eclipse-cdt#455] If constructor arguments fail to resolve, propagate…
Browse files Browse the repository at this point in the history
… failure

This change prevents invalid partial specialisations from being chosen
when
instantiating a template in cases where the expression for the
type/value of a template parameter involves a constructor call.
  • Loading branch information
davmac314 committed Jul 12, 2023
1 parent 54d5e14 commit b436083
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6865,6 +6865,44 @@ public void testSfinae_b() throws Exception {
parseAndCheckBindings();
}

// template <class, typename = void>
// struct A
// {
// using type = int *;
// };
//
// template <class T>
// struct A<T, decltype(void(typename T::p()))>
// {
// using type = typename T::p;
// };
//
// class d { };
//
// class B {
// public:
// using p = typename A<d>::type;
//
// public:
// explicit B(p) {}
// };
//
// int *ip = nullptr;
// B b1 { ip };
// B::p jp = nullptr;
public void testSfinae_c() throws Exception {
BindingAssertionHelper bh = getAssertionHelper();

IVariable varB1 = bh.assertNonProblem("b1");
IType bcls = bh.assertNonProblem("B");
IVariable varJp = bh.assertNonProblem("jp");
IVariable varIp = bh.assertNonProblem("ip");

assertFalse(varB1.getInitialValue() instanceof IProblemBinding);
assertTrue(varB1.getType().isSameType(bcls));
assertTrue(varIp.getType().isSameType(varJp.getType()));
}

// template<typename T>
// struct is_pod {
// static const bool value = __is_pod(T);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.IntegralValue;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.ProblemType;
import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
Expand Down Expand Up @@ -5067,6 +5068,8 @@ public static boolean isUsingPromiscuousBindingResolution() {
*/
public static IType getDeclTypeForEvaluation(ICPPEvaluation eval) {
IType expressionType = eval.getType();
if (expressionType instanceof ProblemType)
return expressionType;
boolean namedEntity = eval instanceof EvalBinding || eval instanceof EvalMemberAccess;
if (!namedEntity && !(expressionType instanceof ICPPReferenceType)) {
switch (eval.getValueCategory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IProblemType;
import org.eclipse.cdt.core.dom.ast.ISemanticProblem;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IValue;
Expand All @@ -42,6 +43,7 @@
import org.eclipse.cdt.internal.core.dom.parser.DependentValue;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.IntegralValue;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
Expand Down Expand Up @@ -416,6 +418,15 @@ public ICPPEvaluation instantiate(InstantiationContext context, int maxDepth) {
if (args == fArguments && type == fInputType)
return this;

// If type or arguments failed to resolve, return INCOMPLETE for SFINAE purposes
if (type instanceof ProblemBinding)
return EvalFixed.INCOMPLETE;
for (ICPPEvaluation arg : args) {
if (arg.getType() instanceof IProblemType) {
return EvalFixed.INCOMPLETE;
}
}

EvalTypeId result = new EvalTypeId(type, getTemplateDefinition(), fRepresentsNewExpression, fUsesBracedInitList,
args);

Expand Down

0 comments on commit b436083

Please sign in to comment.