mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 01:36:01 +02:00
Bug 508254 - Do not allow instantiation of template with invalid non-type template argument
Change-Id: I29472ddda96631147022c4302f9e9b96a1e3d9e6
This commit is contained in:
parent
94734f0fd1
commit
a067fa4afb
2 changed files with 38 additions and 1 deletions
|
@ -9825,4 +9825,41 @@ public class AST2TemplateTests extends AST2TestBase {
|
||||||
// For now, just test that attempting to evaluate doesn't throw an exception.
|
// For now, just test that attempting to evaluate doesn't throw an exception.
|
||||||
waldo.getInitialValue();
|
waldo.getInitialValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2633,7 +2633,7 @@ public class CPPTemplates {
|
||||||
|
|
||||||
static ICPPTemplateArgument matchTemplateParameterAndArgument(ICPPTemplateDefinition template,
|
static ICPPTemplateArgument matchTemplateParameterAndArgument(ICPPTemplateDefinition template,
|
||||||
ICPPTemplateParameter param, ICPPTemplateArgument arg, CPPTemplateParameterMap map, IASTNode point) {
|
ICPPTemplateParameter param, ICPPTemplateArgument arg, CPPTemplateParameterMap map, IASTNode point) {
|
||||||
if (arg == null || !SemanticUtil.isValidType(arg.getTypeValue())) {
|
if (!isValidArgument(arg)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (param instanceof ICPPTemplateTypeParameter) {
|
if (param instanceof ICPPTemplateTypeParameter) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue