[cfe-commits] r117097 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp

Douglas Gregor dgregor at apple.com
Fri Oct 22 08:24:46 PDT 2010


Author: dgregor
Date: Fri Oct 22 10:24:46 2010
New Revision: 117097

URL: http://llvm.org/viewvc/llvm-project?rev=117097&view=rev
Log:
When performing name lookup for a namespace definition, only look into
the current context's redeclaration context, ignoring using
directives. Fixes PR8430.

Added:
    cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp   (with props)
Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=117097&r1=117096&r2=117097&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Oct 22 10:24:46 2010
@@ -3216,15 +3216,17 @@
 
   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.

Added: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp?rev=117097&view=auto
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp (added)
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp Fri Oct 22 10:24:46 2010
@@ -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();
+}

Propchange: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/p2.cpp
------------------------------------------------------------------------------
    svn:mime-type = text/plain





More information about the cfe-commits mailing list