[cfe-commits] r78414 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/Sema/Sema.h lib/Sema/SemaLookup.cpp

John McCall rjmccall at apple.com
Fri Aug 7 16:07:28 PDT 2009


Douglas Gregor wrote:
>> + for (llvm::tie(I, E) = (*AC)->lookup(Name); I != E; ++I) {
>> + Decl *D = *I;
>> + if (!D->isInIdentifierNamespace(Decl::IDNS_Friend))
>> + continue;
>> +
>> + DeclContext *DC = D->getDeclContext();
>> + if (!AssociatedNamespaces.count(DC))
>> + continue;
>> +
>> + CollectFunctionDecl(Functions, D);
>> }
>
> The AssociatedNamespaces.count(DC) check is redundant, right? We'll 
> eliminate duplicates when the function or function template is 
> introduced into the FunctionSet.

Well, (1) the friend decl actually isn't the same object as other 
existing decls, so that won't work, and (2) this isn't meant as a 
redundancy filter anyway.

To deal with (1) quickly — how are redundant declarations handled now? 
Is overload resolution prepared to weed them out, or is it important 
that lookup do it?

As for (2), what I'm trying to do here is handle cases like this:

class A;
namespace B {
void foo(A, int);
}
class A {
friend void B::foo(A, int);
};
...
foo(A(), 5);

Here B::foo should not be considered: A is an associated class, so its 
namespace-scope friend functions become "visible" in their respective 
namespaces, but B is not an associated namespace and so its declarations 
don't count.

There are definitely other ways of approaching this problem, depending 
on how we actually represent friends in the lookup tables, which I'm 
hashing out now. Right now I think the stub code I checked in is 
backwards, actually, and that I should be restricting friend 
declarations found in associated namespaces by the associated classes 
set rather than restricting friend declarations found in associated 
classes by the associated namespaces set.

John.



More information about the cfe-commits mailing list