aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaLookup.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-08-11 14:45:53 +0000
committerDouglas Gregor <dgregor@apple.com>2010-08-11 14:45:53 +0000
commit7f1c547ee6cd413845f7df9713c701f99866f91d (patch)
tree7d94d3aa703e2adf2fc5bda776d81e62ebb058cf /lib/Sema/SemaLookup.cpp
parent6bf1830875673d6bd6c5bfcd65c9dcabfb45958b (diff)
If name lookup finds different type declarations in different scopes
that actually refer to the same underlying type, it is not an ambiguity; add uniquing support based on the canonical type of type declarations. Fixes <rdar://problem/8296180>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110806 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r--lib/Sema/SemaLookup.cpp60
1 files changed, 39 insertions, 21 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index 2e651838df..837cafda15 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -311,7 +311,8 @@ void LookupResult::resolveKind() {
if (ResultKind == Ambiguous) return;
llvm::SmallPtrSet<NamedDecl*, 16> Unique;
-
+ llvm::SmallPtrSet<QualType, 16> UniqueTypes;
+
bool Ambiguous = false;
bool HasTag = false, HasFunction = false, HasNonFunction = false;
bool HasFunctionTemplate = false, HasUnresolved = false;
@@ -323,32 +324,49 @@ void LookupResult::resolveKind() {
NamedDecl *D = Decls[I]->getUnderlyingDecl();
D = cast<NamedDecl>(D->getCanonicalDecl());
+ // Redeclarations of types via typedef can occur both within a scope
+ // and, through using declarations and directives, across scopes. There is
+ // no ambiguity if they all refer to the same type, so unique based on the
+ // canonical type.
+ if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
+ if (!TD->getDeclContext()->isRecord()) {
+ QualType T = SemaRef.Context.getTypeDeclType(TD);
+ if (!UniqueTypes.insert(SemaRef.Context.getCanonicalType(T))) {
+ // The type is not unique; pull something off the back and continue
+ // at this index.
+ Decls[I] = Decls[--N];
+ continue;
+ }
+ }
+ }
+
if (!Unique.insert(D)) {
// If it's not unique, pull something off the back (and
// continue at this index).
Decls[I] = Decls[--N];
+ continue;
+ }
+
+ // Otherwise, do some decl type analysis and then continue.
+
+ if (isa<UnresolvedUsingValueDecl>(D)) {
+ HasUnresolved = true;
+ } else if (isa<TagDecl>(D)) {
+ if (HasTag)
+ Ambiguous = true;
+ UniqueTagIndex = I;
+ HasTag = true;
+ } else if (isa<FunctionTemplateDecl>(D)) {
+ HasFunction = true;
+ HasFunctionTemplate = true;
+ } else if (isa<FunctionDecl>(D)) {
+ HasFunction = true;
} else {
- // Otherwise, do some decl type analysis and then continue.
-
- if (isa<UnresolvedUsingValueDecl>(D)) {
- HasUnresolved = true;
- } else if (isa<TagDecl>(D)) {
- if (HasTag)
- Ambiguous = true;
- UniqueTagIndex = I;
- HasTag = true;
- } else if (isa<FunctionTemplateDecl>(D)) {
- HasFunction = true;
- HasFunctionTemplate = true;
- } else if (isa<FunctionDecl>(D)) {
- HasFunction = true;
- } else {
- if (HasNonFunction)
- Ambiguous = true;
- HasNonFunction = true;
- }
- I++;
+ if (HasNonFunction)
+ Ambiguous = true;
+ HasNonFunction = true;
}
+ I++;
}
// C++ [basic.scope.hiding]p2: