1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Bug 316317: [C++ 0x] Local and unnamed types as template arguments.

This commit is contained in:
Markus Schorn 2010-08-31 12:02:51 +00:00
parent 4adeb3cefb
commit 17241dc891
2 changed files with 54 additions and 9 deletions

View file

@ -5057,4 +5057,41 @@ public class AST2TemplateTests extends AST2BaseTest {
assertSame(ft, inst.getTemplateDefinition());
assertSame(M, inst.getOwner());
}
// template <class T> struct A {
// friend void f(A, T){}
// };
// template <class T> void g(T t) {
// A<T> at;
// f(at, t);
// }
// int main() {
// class X {} x;
// g(x);
// }
public void testUnnamedTypesAsTemplateArgument_316317a() throws Exception {
final String code= getAboveComment();
parseAndCheckBindings(code);
}
// template <class T> class X { };
// template <class T> void f(T t) { }
// struct {} unnamed_obj;
// void f() {
// struct A { };
// enum { e1 };
// typedef struct {} B;
// B b;
// X<A> x1; // OK
// X<A*> x2; // OK
// X<B> x3; // OK
// f(e1); // OK
// f(unnamed_obj); // OK
// f(b); // OK
// }
public void testUnnamedTypesAsTemplateArgument_316317b() throws Exception {
final String code= getAboveComment();
parseAndCheckBindings(code);
}
}

View file

@ -22,6 +22,7 @@ import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexName;
@ -129,15 +130,22 @@ public class CHQueries {
for (IIndexName name : refs) {
IBinding binding= index.findBinding(name);
if (CallHierarchyUI.isRelevantForCallHierarchy(binding)) {
ICElement[] defs= null;
if (binding instanceof ICPPMethod) {
defs = findOverriders(index, (ICPPMethod) binding);
}
if (defs == null) {
defs= IndexUI.findRepresentative(index, binding);
}
if (defs != null && defs.length > 0) {
result.add(defs, name);
for(;;) {
ICElement[] defs= null;
if (binding instanceof ICPPMethod) {
defs = findOverriders(index, (ICPPMethod) binding);
}
if (defs == null) {
defs= IndexUI.findRepresentative(index, binding);
}
if (defs != null && defs.length > 0) {
result.add(defs, name);
} else if (binding instanceof ICPPSpecialization) {
binding= ((ICPPSpecialization) binding).getSpecializedBinding();
if (binding != null)
continue;
}
break;
}
}
}