[cfe-commits] r91096 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp

John McCall rjmccall at apple.com
Thu Dec 10 18:33:26 PST 2009


Author: rjmccall
Date: Thu Dec 10 20:33:26 2009
New Revision: 91096

URL: http://llvm.org/viewvc/llvm-project?rev=91096&view=rev
Log:
Check if the target of a using decl is already declared in this scope before
doing any of the other redeclaration checks.  We were missing a few cases.
Fixes PR 5752.


Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=91096&r1=91095&r2=91096&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Dec 10 20:33:26 2009
@@ -2995,6 +2995,21 @@
   if (isa<UsingShadowDecl>(Target))
     Target = cast<UsingShadowDecl>(Target)->getTargetDecl();
 
+  // If the target happens to be one of the previous declarations, we
+  // don't have a conflict.
+  // 
+  // FIXME: but we might be increasing its access, in which case we
+  // should redeclare it.
+  NamedDecl *NonTag = 0, *Tag = 0;
+  for (LookupResult::iterator I = Previous.begin(), E = Previous.end();
+         I != E; ++I) {
+    NamedDecl *D = (*I)->getUnderlyingDecl();
+    if (D->getCanonicalDecl() == Target->getCanonicalDecl())
+      return false;
+
+    (isa<TagDecl>(D) ? Tag : NonTag) = D;
+  }
+
   if (Target->isFunctionOrFunctionTemplate()) {
     FunctionDecl *FD;
     if (isa<FunctionTemplateDecl>(Target))
@@ -3036,18 +3051,6 @@
 
   // Target is not a function.
 
-  // If the target happens to be one of the previous declarations, we
-  // don't have a conflict.
-  NamedDecl *NonTag = 0, *Tag = 0;
-  for (LookupResult::iterator I = Previous.begin(), E = Previous.end();
-         I != E; ++I) {
-    NamedDecl *D = (*I)->getUnderlyingDecl();
-    if (D->getCanonicalDecl() == Target->getCanonicalDecl())
-      return false;
-
-    (isa<TagDecl>(D) ? Tag : NonTag) = D;
-  }
-
   if (isa<TagDecl>(Target)) {
     // No conflict between a tag and a non-tag.
     if (!Tag) return false;

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=91096&r1=91095&r2=91096&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 Thu Dec 10 20:33:26 2009
@@ -17,3 +17,17 @@
   using ns1::tag;
   using ns2::tag;
 }
+
+// PR 5752
+namespace test1 {
+  namespace ns {
+    void foo();
+  }
+
+  using ns::foo;
+  void foo(int);
+
+  namespace ns {
+    using test1::foo;
+  }
+}





More information about the cfe-commits mailing list