[cfe-commits] r110806 - in /cfe/trunk: lib/Sema/SemaLookup.cpp test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp test/CXX/dcl.dcl/basic.namespace/namespace.udir/p6.cpp
Douglas Gregor
dgregor at apple.com
Wed Aug 11 07:45:53 PDT 2010
Author: dgregor
Date: Wed Aug 11 09:45:53 2010
New Revision: 110806
URL: http://llvm.org/viewvc/llvm-project?rev=110806&view=rev
Log:
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>.
Added:
cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p6.cpp (with props)
Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=110806&r1=110805&r2=110806&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Aug 11 09:45:53 2010
@@ -311,7 +311,8 @@
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 @@
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];
- } else {
- // Otherwise, do some decl type analysis and then continue.
+ 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 {
- if (HasNonFunction)
- Ambiguous = true;
- HasNonFunction = true;
- }
- I++;
+ 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++;
}
// C++ [basic.scope.hiding]p2:
Modified: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp?rev=110806&r1=110805&r2=110806&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp Wed Aug 11 09:45:53 2010
@@ -31,3 +31,4 @@
using test1::foo;
}
}
+
Added: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p6.cpp?rev=110806&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p6.cpp (added)
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p6.cpp Wed Aug 11 09:45:53 2010
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// <rdar://problem/8296180>
+typedef int pid_t;
+namespace ns {
+ typedef int pid_t;
+}
+using namespace ns;
+pid_t x;
+
+struct A { };
+namespace ns {
+ typedef ::A A;
+}
+A a;
Propchange: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p6.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p6.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udir/p6.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list