1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-06 15:55:47 +02:00

Bug 329795: Resolution of nested typedef specializations.

This commit is contained in:
Markus Schorn 2010-11-11 16:31:12 +00:00
parent 871733c29e
commit a754d86200
2 changed files with 37 additions and 2 deletions

View file

@ -5135,5 +5135,24 @@ public class AST2TemplateTests extends AST2BaseTest {
public void testPartialOrderingForConversions_Bug326900() throws Exception {
parseAndCheckBindings();
}
// struct S { int foo; };
// template<typename T> struct L {
// typedef T& CR;
// template<bool> struct _CI {
// CR m();
// };
// typedef _CI<true> CI;
// };
// void test() {
// L<S>::CI l;
// l.m().foo = 1;
// }
public void testNestedTypedefSpecialization_Bug329795() throws Exception {
String code= getAboveComment();
BindingAssertionHelper bh= new BindingAssertionHelper(code, true);
ICPPField f1= bh.assertNonProblem("foo;", 3);
IBinding f2= bh.assertNonProblem("foo =", 3);
assertSame(f1, f2);
}
}

View file

@ -54,12 +54,28 @@ public abstract class CPPSpecialization extends PlatformObject implements ICPPSp
public IType specializeType(IType type) {
if (owner instanceof ICPPClassSpecialization) {
return CPPTemplates.instantiateType(type, getTemplateParameterMap(), -1, (ICPPClassSpecialization) owner);
ICPPClassSpecialization within = getWithin((ICPPClassSpecialization) owner);
return CPPTemplates.instantiateType(type, getTemplateParameterMap(), -1, within);
} else {
return CPPTemplates.instantiateType(type, getTemplateParameterMap(), -1, null);
}
}
private ICPPClassSpecialization getWithin(ICPPClassSpecialization within) {
ICPPClassType orig = within.getSpecializedBinding();
for(;;) {
IBinding o1 = within.getOwner();
IBinding o2 = orig.getOwner();
if (!(o1 instanceof ICPPClassSpecialization && o2 instanceof ICPPClassType))
return within;
ICPPClassSpecialization nextWithin = (ICPPClassSpecialization) o1;
orig= (ICPPClassType) o2;
if (orig.isSameType(nextWithin))
return within;
within= nextWithin;
}
}
public IType[] specializeTypePack(ICPPParameterPackType type) {
if (owner instanceof ICPPClassSpecialization) {
return CPPTemplates.instantiateTypes(new IType[]{type}, getTemplateParameterMap(), -1, (ICPPClassSpecialization) owner);