mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 352859: Matching of template template parameters.
This commit is contained in:
parent
df4c17ffdc
commit
947aacd42b
2 changed files with 49 additions and 25 deletions
|
@ -4532,8 +4532,8 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
// X<A> xa; // okay
|
// X<A> xa; // okay
|
||||||
// X<B> xb; // ill-formed: default arguments for the parameters of a template template argument are ignored
|
// X<B> xb; // ill-formed: default arguments for the parameters of a template template argument are ignored
|
||||||
// X<C> xc; // ill-formed: a template parameter pack does not match a template parameter
|
// X<C> xc; // ill-formed: a template parameter pack does not match a template parameter
|
||||||
// Y<A> ya; // ill-formed: a template parameter pack does not match a template parameter
|
// Y<A> ya; // okay
|
||||||
// Y<B> yb; // ill-formed: a template parameter pack does not match a template parameter
|
// Y<B> yb; // okay
|
||||||
// Y<C> yc; // okay
|
// Y<C> yc; // okay
|
||||||
public void testVariadicTemplateExamples_280909f() throws Exception {
|
public void testVariadicTemplateExamples_280909f() throws Exception {
|
||||||
final String code= getAboveComment();
|
final String code= getAboveComment();
|
||||||
|
@ -4541,8 +4541,8 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
bh.assertNonProblem("X<A>", 4);
|
bh.assertNonProblem("X<A>", 4);
|
||||||
bh.assertProblem("X<B>", 4);
|
bh.assertProblem("X<B>", 4);
|
||||||
bh.assertProblem("X<C>", 4);
|
bh.assertProblem("X<C>", 4);
|
||||||
bh.assertProblem("Y<A>", 4);
|
bh.assertNonProblem("Y<A>", 4);
|
||||||
bh.assertProblem("Y<B>", 4);
|
bh.assertNonProblem("Y<B>", 4);
|
||||||
bh.assertNonProblem("Y<C>", 4);
|
bh.assertNonProblem("Y<C>", 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5439,4 +5439,19 @@ public class AST2TemplateTests extends AST2BaseTest {
|
||||||
public void testTemplateParameterWithoutName_352266() throws Exception {
|
public void testTemplateParameterWithoutName_352266() throws Exception {
|
||||||
parseAndCheckBindings();
|
parseAndCheckBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<template<typename, typename...> class T> struct CTTP{ };
|
||||||
|
//
|
||||||
|
// template<typename T> struct CT1{ };
|
||||||
|
// template<typename T1, typename T2> struct CT2{ };
|
||||||
|
// template<typename T1, typename T2, typename T3> struct CT3{ };
|
||||||
|
// template<typename T1, typename T2, typename T3, typename... T4> struct CT4{ };
|
||||||
|
//
|
||||||
|
// typedef CTTP<CT1> a;
|
||||||
|
// typedef CTTP<CT2> b;
|
||||||
|
// typedef CTTP<CT3> c;
|
||||||
|
// typedef CTTP<CT4> d;
|
||||||
|
public void testTemplateTemplateParameterMatching_352859() throws Exception {
|
||||||
|
parseAndCheckBindings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1981,7 +1981,7 @@ public class CPPTemplates {
|
||||||
try {
|
try {
|
||||||
pParams = ((ICPPTemplateTemplateParameter) param).getTemplateParameters();
|
pParams = ((ICPPTemplateTemplateParameter) param).getTemplateParameters();
|
||||||
aParams = ((ICPPTemplateDefinition) t).getTemplateParameters();
|
aParams = ((ICPPTemplateDefinition) t).getTemplateParameters();
|
||||||
if (!compareTemplateParameters(pParams, aParams))
|
if (!matchTemplateTemplateParameters(pParams, aParams))
|
||||||
return null;
|
return null;
|
||||||
} catch (DOMException e) {
|
} catch (DOMException e) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -2015,48 +2015,57 @@ public class CPPTemplates {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean compareTemplateParameters(ICPPTemplateParameter[] params1,
|
private static boolean matchTemplateTemplateParameters(ICPPTemplateParameter[] pParams,
|
||||||
ICPPTemplateParameter[] params2) throws DOMException {
|
ICPPTemplateParameter[] aParams) throws DOMException {
|
||||||
int size = params1.length;
|
int pi=0;
|
||||||
if (params2.length != size) {
|
int ai=0;
|
||||||
return false;
|
while (pi < pParams.length && ai < aParams.length) {
|
||||||
}
|
final ICPPTemplateParameter pp = pParams[pi];
|
||||||
|
final ICPPTemplateParameter ap = aParams[ai];
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
// A parameter pack does not match a regular template parameter.
|
||||||
final ICPPTemplateParameter p1 = params1[i];
|
if (ap.isParameterPack() && !pp.isParameterPack())
|
||||||
final ICPPTemplateParameter p2 = params2[i];
|
|
||||||
if (p1.isParameterPack() != p2.isParameterPack())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
boolean pb= p1 instanceof ICPPTemplateTypeParameter;
|
|
||||||
boolean ab= p2 instanceof ICPPTemplateTypeParameter;
|
boolean pb= pp instanceof ICPPTemplateTypeParameter;
|
||||||
|
boolean ab= ap instanceof ICPPTemplateTypeParameter;
|
||||||
if (pb != ab)
|
if (pb != ab)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (pb) {
|
if (pb) {
|
||||||
// Both are template type parameters
|
// Both are template type parameters
|
||||||
} else {
|
} else {
|
||||||
pb= p1 instanceof ICPPTemplateNonTypeParameter;
|
pb= pp instanceof ICPPTemplateNonTypeParameter;
|
||||||
ab= p2 instanceof ICPPTemplateNonTypeParameter;
|
ab= ap instanceof ICPPTemplateNonTypeParameter;
|
||||||
if (pb != ab)
|
if (pb != ab)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (pb) {
|
if (pb) {
|
||||||
// Both are non-type parameters
|
// Both are non-type parameters
|
||||||
} else {
|
} else {
|
||||||
if (!(p1 instanceof ICPPTemplateTemplateParameter) ||
|
if (!(pp instanceof ICPPTemplateTemplateParameter) ||
|
||||||
!(p2 instanceof ICPPTemplateTemplateParameter)) {
|
!(ap instanceof ICPPTemplateTemplateParameter)) {
|
||||||
assert false;
|
assert false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compareTemplateParameters(((ICPPTemplateTemplateParameter) p1).getTemplateParameters(),
|
if (!matchTemplateTemplateParameters(((ICPPTemplateTemplateParameter) pp).getTemplateParameters(),
|
||||||
((ICPPTemplateTemplateParameter) p2).getTemplateParameters()) )
|
((ICPPTemplateTemplateParameter) ap).getTemplateParameters()) )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!pp.isParameterPack())
|
||||||
|
pi++;
|
||||||
|
ai++;
|
||||||
}
|
}
|
||||||
|
if (pi < pParams.length) {
|
||||||
|
if (pi == pParams.length - 1 && pParams[pi].isParameterPack())
|
||||||
return true;
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ai == aParams.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue