[cfe-dev] [Patch] Refactor Sema::CppLookupName
Douglas Gregor
dgregor at apple.com
Wed Feb 4 15:22:36 PST 2009
On Feb 4, 2009, at 2:23 PM, Piotr Rak wrote:
> Attached refactors Sema::CppNameLookup in way, we do not reapeat
> looking into same DeclContexts, also looks now it looks less chaotic
> IMO :)
> It also fixes MergeLookupResults. My recent patch caused it fail in
> same cases, which is noticable with CppNameLookup change.
This doesn't look right:
+ if (HasFuncs) {
+ // Filter out non-FunctionDecls from result set.
+ for (DeclsSetTy::iterator FD=DI; FD!=DEnd; FD++)
+ if (!isa<FunctionDecl>(*FD)) FoundDecls.erase(*FD);
+ FoundLen = FoundDecls.size();
+ }
It's not that when we have functions we ignore everything else.
Rather, object names (for functions, enumerators, variables, etc.)
hide tag names (structs, enums, etc.), but only if those names
themselves aren't ambiguous. I added this to the end of using-
directive.cpp to test my theory:
namespace Ni {
int i();
}
namespace NiTest {
using namespace A;
using namespace Ni;
int test() {
return i; // expected-error{{ambiguous}}
}
}
and, rather than producing an ambiguity, it complains that it can't
return an int(void) from a function whose return type is "int". I
suspect that A::i is getting thrown out by the loop mentioned above.
I really think that FoundOverloaded, and the optimization it's
attempting to do, is overly complicating MergeLookupResults. I suggest
that the FoundOverloaded optimization be removed for now, until we
have the semantics solidly implemented. Every Decl that we see (either
due to LResult::Found or LResult::FoundOverloaded) gets dumped into
FoundDecls. For TagDecls, get the canonical tag decl before putting
the decl into FoundDecls.
At the end of the main loop in MergeLookupResults, FoundDecls will
contain all of the non-unique decls. We can go through those keeping
track of what kinds of names we see: object names, function names, and
tag names. Then, determine whether they conflict or one hides the
other, generating an ambiguous lookup if they conflict and hiding the
tag names if they don't conflict.
- Doug
More information about the cfe-dev
mailing list