]> granicus.if.org Git - clang/commitdiff
Check if the target of a using decl is already declared in this scope before
authorJohn McCall <rjmccall@apple.com>
Fri, 11 Dec 2009 02:33:26 +0000 (02:33 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 11 Dec 2009 02:33:26 +0000 (02:33 +0000)
doing any of the other redeclaration checks.  We were missing a few cases.
Fixes PR 5752.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91096 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p10.cpp

index 75021c28509fabc705f5fdd2dd180dc0189e6689..7d16e9b2b0f97ef102a34ef299f9f96f00159046 100644 (file)
@@ -2995,6 +2995,21 @@ bool Sema::CheckUsingShadowDecl(UsingDecl *Using, NamedDecl *Orig,
   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 @@ bool Sema::CheckUsingShadowDecl(UsingDecl *Using, NamedDecl *Orig,
 
   // 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;
index e6b8fc1d8f4636f9922431f7a3a38c8da90f96dc..00d109e67516b3f6ffe0d9085ca2b2e92b24226d 100644 (file)
@@ -17,3 +17,17 @@ namespace test0 {
   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;
+  }
+}