1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Bug 327069: ADL for class specializations.

This commit is contained in:
Markus Schorn 2010-10-07 12:14:53 +00:00
parent 4ff02dcc5d
commit ae87b6d440
2 changed files with 58 additions and 29 deletions

View file

@ -5100,4 +5100,17 @@ public class AST2TemplateTests extends AST2BaseTest {
g= bh.assertNonProblem("g, 1)", 1); g= bh.assertNonProblem("g, 1)", 1);
assertSame(g1, g); assertSame(g1, g);
} }
// template <class T> class Ptr{};
// namespace ns {
// class T {};
// void f(Ptr<T>);
// }
// void test() {
// Ptr<ns::T> parm;
// f(parm);
// }
public void testADLForTemplateSpecializations_Bug327069() throws Exception {
parseAndCheckBindings();
}
} }

View file

@ -652,53 +652,69 @@ public class CPPSemantics {
IType[] ps = data.getFunctionArgumentTypes(); IType[] ps = data.getFunctionArgumentTypes();
Set<ICPPNamespaceScope> namespaces = new HashSet<ICPPNamespaceScope>(2); Set<ICPPNamespaceScope> namespaces = new HashSet<ICPPNamespaceScope>(2);
ObjectSet<ICPPClassType> classes = new ObjectSet<ICPPClassType>(2); ObjectSet<IType> handled = new ObjectSet<IType>(2);
for (IType p : ps) { for (IType p : ps) {
p = getUltimateType(p, true);
try { try {
getAssociatedScopes(p, namespaces, classes, data.tu); getAssociatedScopes(p, namespaces, handled, data.tu);
} catch (DOMException e) { } catch (DOMException e) {
} }
} }
return namespaces; return namespaces;
} }
// 3.4.2-2
private static void getAssociatedScopes(IType t, Set<ICPPNamespaceScope> namespaces, private static void getAssociatedScopes(IType t, Set<ICPPNamespaceScope> namespaces,
ObjectSet<ICPPClassType> classes, CPPASTTranslationUnit tu) throws DOMException { ObjectSet<IType> handled, CPPASTTranslationUnit tu) throws DOMException {
// 3.4.2-2 t = getNestedType(t, TDEF | CVTYPE | PTR | ARRAY | REF);
if (t instanceof ICPPClassType) { if (t instanceof IBinding) {
if (handled.containsKey(t))
return;
handled.put(t);
IBinding owner= ((IBinding) t).getOwner();
if (owner instanceof ICPPClassType) {
getAssociatedScopes((IType) owner, namespaces, handled, tu);
} else {
getAssociatedNamespaceScopes(getContainingNamespaceScope((IBinding) t, tu), namespaces);
}
}
if (t instanceof ICPPClassType && !(t instanceof ICPPClassTemplate)) {
ICPPClassType ct= (ICPPClassType) t; ICPPClassType ct= (ICPPClassType) t;
if (!classes.containsKey(ct)) { ICPPBase[] bases = ct.getBases();
classes.put(ct); for (ICPPBase base : bases) {
getAssociatedNamespaceScopes(getContainingNamespaceScope((IBinding) t, tu), namespaces); if (!(base instanceof IProblemBinding)) {
IBinding b = base.getBaseClass();
ICPPClassType cls = (ICPPClassType) t; if (b instanceof IType)
ICPPBase[] bases = cls.getBases(); getAssociatedScopes((IType) b, namespaces, handled, tu);
for (ICPPBase base : bases) { }
if (base instanceof IProblemBinding) }
continue; // Furthermore, if T is a class template ...
IBinding b = base.getBaseClass(); // * ... types of the template arguments for template type parameters
if (b instanceof IType) // (excluding template template parameters);
getAssociatedScopes((IType) b, namespaces, classes, tu); // * ... owners of which any template template arguments are members;
} if (ct instanceof ICPPTemplateInstance) {
} ICPPTemplateArgument[] args = ((ICPPTemplateInstance) ct).getTemplateArguments();
} else if (t instanceof IEnumeration) { for (ICPPTemplateArgument arg : args) {
getAssociatedNamespaceScopes(getContainingNamespaceScope((IBinding) t, tu), namespaces); if (arg.isTypeValue()) {
getAssociatedScopes(arg.getTypeValue(), namespaces, handled, tu);
}
}
}
} else if (t instanceof IFunctionType) { } else if (t instanceof IFunctionType) {
IFunctionType ft = (IFunctionType) t; IFunctionType ft = (IFunctionType) t;
getAssociatedScopes(ft.getReturnType(), namespaces, handled, tu);
getAssociatedScopes(getUltimateType(ft.getReturnType(), true), namespaces, classes, tu);
IType[] ps = ft.getParameterTypes(); IType[] ps = ft.getParameterTypes();
for (IType element : ps) { for (IType pt : ps) {
getAssociatedScopes(getUltimateType(element, true), namespaces, classes, tu); getAssociatedScopes(pt, namespaces, handled, tu);
} }
} else if (t instanceof ICPPPointerToMemberType) { } else if (t instanceof ICPPPointerToMemberType) {
IType binding = ((ICPPPointerToMemberType) t).getMemberOfClass(); final ICPPPointerToMemberType pmt = (ICPPPointerToMemberType) t;
getAssociatedScopes(binding, namespaces, classes, tu); getAssociatedScopes(pmt.getMemberOfClass(), namespaces, handled, tu);
getAssociatedScopes(pmt.getType(), namespaces, handled, tu);
} else if (t instanceof FunctionSetType) { } else if (t instanceof FunctionSetType) {
FunctionSetType fst= (FunctionSetType) t; FunctionSetType fst= (FunctionSetType) t;
for (ICPPFunction fn : fst.getFunctionSet()) { for (ICPPFunction fn : fst.getFunctionSet()) {
getAssociatedScopes(fn.getType(), namespaces, classes, tu); getAssociatedScopes(fn.getType(), namespaces, handled, tu);
} }
} }
} }