Skip to content

Commit 0ebbd0e

Browse files
davmac314jonahgraham
authored andcommitted
Improve template specialisation selection (#1267)
A numeric or boolean template argument in a partial specialisation needs to be resolved, which isn't currently being handled.
1 parent 00290b2 commit 0ebbd0e

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,26 @@ public void test14_5_4_1s2_MatchingTemplateSpecializations() throws Exception {
591591
assertSame(R3.getTemplateDefinition(), A4);
592592
}
593593

594+
// template <typename T> constexpr bool consume_r1() { return true; }
595+
// template <class T1, bool EN = true> class A { };
596+
// template <class T1> class A <T1, (bool)consume_r1<T1>()> { };
597+
// A<int> a1; // uses specialisation
598+
public void testPrimitiveMatchingSpecializations() throws Exception {
599+
IASTTranslationUnit tu = parse(getAboveComment(), CPP);
600+
NameCollector col = new NameCollector();
601+
tu.accept(col);
602+
603+
ICPPClassTemplate A1 = (ICPPClassTemplate) col.getName(4).resolveBinding();
604+
ICPPClassTemplate A2 = (ICPPClassTemplate) col.getName(6).resolveBinding();
605+
606+
assertTrue(A2 instanceof ICPPClassTemplatePartialSpecialization);
607+
assertSame(((ICPPClassTemplatePartialSpecialization) A2).getPrimaryClassTemplate(), A1);
608+
609+
ICPPTemplateInstance R1 = (ICPPTemplateInstance) col.getName(12).resolveBinding();
610+
611+
assertSame(R1.getTemplateDefinition(), A2);
612+
}
613+
594614
// template <class T> void f(T);
595615
// template <class T> void f(T*);
596616
// template <> void f(int); //ok

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,9 @@ private boolean fromTemplateArgument(ICPPTemplateArgument p, ICPPTemplateArgumen
877877
}
878878
}
879879
IValue sval = a.getNonTypeValue();
880+
tval = CPPTemplates.instantiateValue(tval, InstantiationContext.forDeduction(fDeducedArgs),
881+
IntegralValue.MAX_RECURSION_DEPTH);
882+
880883
return tval.equals(sval);
881884
}
882885

0 commit comments

Comments
 (0)