1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 508254 - Do not allow instantiation of template with invalid non-type template argument

Change-Id: I29472ddda96631147022c4302f9e9b96a1e3d9e6
This commit is contained in:
Nathan Ridge 2016-12-01 03:27:31 -05:00
parent a93b94b822
commit 0d02aea069
2 changed files with 38 additions and 1 deletions

View file

@ -9821,4 +9821,41 @@ public class AST2TemplateTests extends AST2TestBase {
IVariable waldo = helper.assertNonProblem("waldo");
helper.assertVariableValue("waldo", -13);
}
// template<int P, int Q>
// struct gcd : gcd<Q, P % Q> {};
//
// template<int P>
// struct gcd<P, 0> {
// static constexpr int value = P;
// };
//
// template<int Q>
// struct gcd<0, Q> {
// static constexpr int value = Q;
// };
//
// template<int N, int D = 1>
// struct ratio {
// static constexpr int den = D / gcd<N, D>::value;
// };
//
// constexpr int foo(int) {
// return 42;
// }
//
// struct S : public ratio<foo("")> {};
//
// template<typename R1, typename R2>
// struct ratio_multiply {
// static constexpr int div = gcd<1, R1::den>::value;
// typedef ratio<1, R1::den / div> type;
// };
//
// typedef ratio_multiply<S, ratio<1>>::type waldo;
public void testOOM_508254() throws Exception {
BindingAssertionHelper helper = getAssertionHelper();
// Just check that resolution does not throw an exception.
helper.findName("waldo", 5).resolveBinding();
}
}

View file

@ -2633,7 +2633,7 @@ public class CPPTemplates {
static ICPPTemplateArgument matchTemplateParameterAndArgument(ICPPTemplateDefinition template,
ICPPTemplateParameter param, ICPPTemplateArgument arg, CPPTemplateParameterMap map, IASTNode point) {
if (arg == null || !SemanticUtil.isValidType(arg.getTypeValue())) {
if (!isValidArgument(arg)) {
return null;
}
if (param instanceof ICPPTemplateTypeParameter) {