diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 47209ec482a..381ccac2afb 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -8643,4 +8643,38 @@ public class AST2TemplateTests extends AST2TestBase { IVariable var2 = helper.assertNonProblem("var2"); assertSameType(var1.getType(), var2.getType()); } + + // template + // struct integral_constant { + // static const bool value = true; + // }; + // + // template + // struct meta2 { + // struct Test {}; + // + // enum { + // value = sizeof((Test())) + // }; + // }; + // + // struct meta : integral_constant::value> {}; + // + // template + // struct base { + // int waldo; + // }; + // + // template + // struct S : base { + // using base::waldo; + // }; + // + // int main() { + // S s; + // s.waldo = 42; + // } + public void testClassSpecializationInEnumerator_457511() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index 79e66aea99d..f4e45332690 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -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