Community
Participate
Working Groups
To reproduce create a project with two files: test.h ------ template <typename T> struct C { void m(const T& p); }; //namespace { struct A { A() {} }; //} test.cc ------- #include "test.h" void test() { C<A> c; A a; c.m(a); } 1. Rebuild the index. All symbols are resolved. 2. Uncomment the two commented out lines in test.h -- 'm' in test.cc becomes unresolved. 3. Rebuild the index -- 'm' is resolved again.
I understand why that happens: * We have two different bindings for 'struct A' depending on whether it is enclosed by an unnamed namespace or not. * The instance C<A> is found via string representation (ASTTypeUtil) of its argument. The string representation does not distinguish between the two bindings. A potential way to fix that: We could move the concept of a file-local binding from IIndexBinding to IBinding. With that it can become part of the type signature.
(In reply to comment #1) It seems that the logic in ASTTypeUtil.appendNameCheckAnonymous is problematic since it doesn't distinguish between an anonymous namespace and its container namespace. We could potentially represent an anonymous namespace by a special string pattern containing the name of the file where the namespace is defined, for example {filename}. During name lookup we can match against all anonymous workspaces that are defined in directly or indirectly included files.
(In reply to comment #2) The approach described in comment #2 won't work in a situation like: header1.h --------- namespace { class A {}; } header2.h --------- namespace { A* a; } source.cc --------- #include "header1.h" #include "header2.h" a = new A; It looks like there is no alternative to the solution based on file-local bindings.