aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaLookup.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-11-17 07:50:12 +0000
committerJohn McCall <rjmccall@apple.com>2009-11-17 07:50:12 +0000
commit314be4e7d8ef86202b0ec8e9ff0dcef853db3320 (patch)
treebc40ef33ff7c555ca0b74e30ca124be4581f2cef /lib/Sema/SemaLookup.cpp
parentc5419cc8655c215c8c0c8dc3976a527ca867f655 (diff)
Store "sugared" decls in LookupResults (i.e. decl aliases like using declarations);
strip the sugar off in getFoundDecl() and getAsSingleDecl(), but leave it on for clients like overload resolution who want to use the iterators. Refactor a few pieces of overload resolution to strip off using declarations in a single place. Don't do anything useful with the extra context knowledge yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89061 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r--lib/Sema/SemaLookup.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index 58b95fc679..70dca799ae 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -254,21 +254,21 @@ void Sema::LookupResult::resolveKind() {
bool Ambiguous = false;
bool HasTag = false, HasFunction = false, HasNonFunction = false;
+ bool HasUnresolved = false;
unsigned UniqueTagIndex = 0;
unsigned I = 0;
while (I < N) {
- NamedDecl *D = Decls[I];
- assert(D == D->getUnderlyingDecl());
+ NamedDecl *D = Decls[I]->getUnderlyingDecl();
+ D = cast<NamedDecl>(D->getCanonicalDecl());
- NamedDecl *CanonD = cast<NamedDecl>(D->getCanonicalDecl());
- if (!Unique.insert(CanonD)) {
+ if (!Unique.insert(D)) {
// If it's not unique, pull something off the back (and
// continue at this index).
Decls[I] = Decls[--N];
} else if (isa<UnresolvedUsingDecl>(D)) {
- // FIXME: proper support for UnresolvedUsingDecls.
+ HasUnresolved = true;
Decls[I] = Decls[--N];
} else {
// Otherwise, do some decl type analysis and then continue.
@@ -288,6 +288,13 @@ void Sema::LookupResult::resolveKind() {
}
}
+ // Postpone all other decisions if we have an unresolved decl, even
+ // if we can prove ambiguity. We can probably do better than this.
+ if (HasUnresolved) {
+ ResultKind = LookupResult::FoundOverloaded;
+ return;
+ }
+
// C++ [basic.scope.hiding]p2:
// A class name or enumeration name can be hidden by the name of
// an object, function, or enumerator declared in the same
@@ -329,7 +336,7 @@ void Sema::LookupResult::resolveKind() {
NamedDecl *Sema::LookupResult::getAsSingleDecl(ASTContext &C) const {
size_t size = Decls.size();
if (size == 0) return 0;
- if (size == 1) return *begin();
+ if (size == 1) return (*begin())->getUnderlyingDecl();
if (isAmbiguous()) return 0;
@@ -339,9 +346,7 @@ NamedDecl *Sema::LookupResult::getAsSingleDecl(ASTContext &C) const {
= OverloadedFunctionDecl::Create(C, (*I)->getDeclContext(),
(*I)->getDeclName());
for (; I != E; ++I) {
- NamedDecl *ND = *I;
- assert(ND->getUnderlyingDecl() == ND
- && "decls in lookup result should have redirections stripped");
+ NamedDecl *ND = (*I)->getUnderlyingDecl();
assert(ND->isFunctionOrFunctionTemplate());
if (isa<FunctionDecl>(ND))
Ovl->addOverload(cast<FunctionDecl>(ND));