]> granicus.if.org Git - clang/commitdiff
When performing name lookup for a namespace definition, only look into
authorDouglas Gregor <dgregor@apple.com>
Fri, 22 Oct 2010 15:24:46 +0000 (15:24 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 22 Oct 2010 15:24:46 +0000 (15:24 +0000)
the current context's redeclaration context, ignoring using
directives. Fixes PR8430.

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

lib/Sema/SemaDeclCXX.cpp
test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp [new file with mode: 0644]

index 2f3b2f4262e34eb54b46b766f9afc8669e04bb39..564dab49de83bcab440906fd4a0535d2670be282 100644 (file)
@@ -3216,15 +3216,17 @@ Decl *Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
 
   if (II) {
     // C++ [namespace.def]p2:
-    // The identifier in an original-namespace-definition shall not have been
-    // previously defined in the declarative region in which the
-    // original-namespace-definition appears. The identifier in an
-    // original-namespace-definition is the name of the namespace. Subsequently
-    // in that declarative region, it is treated as an original-namespace-name.
-
-    NamedDecl *PrevDecl
-      = LookupSingleName(DeclRegionScope, II, IdentLoc, LookupOrdinaryName,
-                         ForRedeclaration);
+    //   The identifier in an original-namespace-definition shall not
+    //   have been previously defined in the declarative region in
+    //   which the original-namespace-definition appears. The
+    //   identifier in an original-namespace-definition is the name of
+    //   the namespace. Subsequently in that declarative region, it is
+    //   treated as an original-namespace-name.
+    //
+    // Since namespace names are unique in their scope, and we don't
+    // look through using directives, just
+    DeclContext::lookup_result R = CurContext->getRedeclContext()->lookup(II);
+    NamedDecl *PrevDecl = R.first == R.second? 0 : *R.first;
 
     if (NamespaceDecl *OrigNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl)) {
       // This is an extended namespace definition.
diff --git a/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp b/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp
new file mode 100644 (file)
index 0000000..411c16c
--- /dev/null
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR8430
+namespace N {
+  class A { };
+}
+
+namespace M { }
+
+using namespace M;
+
+namespace N {
+  namespace M {
+  } 
+}
+
+namespace M {
+  namespace N {
+  }
+}
+
+namespace N {
+  A *getA();
+}