1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 20:35:38 +02:00

Bug 457511 - Instantiation of nested class used inside enumerator

Change-Id: I45f8f49ab1aa45b8f1309bb465ca08b001762173
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Sergey Prigogin 2015-01-18 02:08:00 -05:00
parent b447d066aa
commit 686ad904b2
2 changed files with 50 additions and 13 deletions

View file

@ -8643,4 +8643,38 @@ public class AST2TemplateTests extends AST2TestBase {
IVariable var2 = helper.assertNonProblem("var2");
assertSameType(var1.getType(), var2.getType());
}
// template <bool>
// struct integral_constant {
// static const bool value = true;
// };
//
// template <class>
// struct meta2 {
// struct Test {};
//
// enum {
// value = sizeof((Test()))
// };
// };
//
// struct meta : integral_constant<meta2<int>::value> {};
//
// template <int>
// struct base {
// int waldo;
// };
//
// template <typename>
// struct S : base<meta::value> {
// using base<meta::value>::waldo;
// };
//
// int main() {
// S<int> s;
// s.waldo = 42;
// }
public void testClassSpecializationInEnumerator_457511() throws Exception {
parseAndCheckBindings();
}
}

View file

@ -1008,11 +1008,9 @@ public class CPPTemplates {
}
public static ICPPClassSpecialization getSpecializationContext(IBinding owner) {
if (owner instanceof ICPPEnumerationSpecialization)
owner = owner.getOwner();
if (!(owner instanceof ICPPClassSpecialization))
ICPPClassSpecialization within = getContextClassSpecialization(owner);
if (within == null)
return null;
ICPPClassSpecialization within= (ICPPClassSpecialization) owner;
ICPPClassType orig = within.getSpecializedBinding();
while (true) {
IBinding o1 = within.getOwner();
@ -1027,6 +1025,14 @@ public class CPPTemplates {
}
}
protected static ICPPClassSpecialization getContextClassSpecialization(IBinding owner) {
if (owner instanceof ICPPEnumerationSpecialization)
owner = owner.getOwner();
if (owner instanceof ICPPClassSpecialization)
return (ICPPClassSpecialization) owner;
return null;
}
public static IValue instantiateValue(IValue value, ICPPTemplateParameterMap tpMap, int packOffset,
ICPPTypeSpecialization within, int maxdepth, IASTNode point) {
if (value == null)
@ -1372,21 +1378,22 @@ public class CPPTemplates {
if (within != null && type instanceof IBinding) {
IType unwound= getNestedType(type, TDEF);
if (unwound instanceof ICPPClassType && unwound.isSameType(getSpecializedType(within))) {
ICPPClassSpecialization withinClass = getContextClassSpecialization(within);
if (unwound instanceof ICPPClassType && unwound.isSameType(withinClass.getSpecializedBinding())) {
// Convert (partial) class-templates (specializations) to the more specialized
// version.
if (within instanceof ICPPClassTemplate || !(unwound instanceof ICPPClassTemplate))
return within;
if (withinClass instanceof ICPPClassTemplate || !(unwound instanceof ICPPClassTemplate))
return withinClass;
}
IBinding typeAsBinding= (IBinding) type;
IBinding owner= typeAsBinding.getOwner();
if (owner instanceof IType) {
final IType ownerAsType = getNestedType((IType) owner, TDEF);
Object newOwner= owner;
if (ownerAsType instanceof ICPPClassType && ownerAsType.isSameType(getSpecializedType(within))) {
if (ownerAsType instanceof ICPPClassType && ownerAsType.isSameType(withinClass.getSpecializedBinding())) {
// Convert (partial) class-templates (specializations) that are used as
// owner of another binding, to the more specialized version.
newOwner= within;
newOwner= withinClass;
} else {
newOwner= instantiateType(ownerAsType, tpMap, packOffset, within, point);
}
@ -1463,10 +1470,6 @@ public class CPPTemplates {
}
}
private static IType getSpecializedType(ICPPTypeSpecialization typeSpecialization) {
return (IType) typeSpecialization.getSpecializedBinding();
}
/**
* Specialize a template parameter of a nested template by subtituting values for the template
* parameters of enclosing templates into the template parameter's default value and, in the