[cfe-commits] r53667 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/cxx-namespace.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Wed Jul 16 00:45:46 PDT 2008


Author: akirtzidis
Date: Wed Jul 16 02:45:46 2008
New Revision: 53667

URL: http://llvm.org/viewvc/llvm-project?rev=53667&view=rev
Log:
When checking for name collision between a tag and a previously defined namespace, the collision occured even when the tag was in a different nested scope.
Fix it by taking into account the scope when checking for namespace-tag name collisions.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/cxx-namespace.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jul 16 02:45:46 2008
@@ -1733,11 +1733,14 @@
       // scope, e.g. "struct foo; void bar() { struct foo; }", just create a new
       // type.
     } else {
-      // The tag name clashes with a namespace name, issue an error and recover
-      // by making this tag be anonymous.
-      Diag(NameLoc, diag::err_redefinition_different_kind, Name->getName());
-      Diag(PrevDecl->getLocation(), diag::err_previous_definition);
-      Name = 0;
+      // PrevDecl is a namespace.
+      if (IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
+        // The tag name clashes with a namespace name, issue an error and recover
+        // by making this tag be anonymous.
+        Diag(NameLoc, diag::err_redefinition_different_kind, Name->getName());
+        Diag(PrevDecl->getLocation(), diag::err_previous_definition);
+        Name = 0;
+      }
     }
   }
   

Modified: cfe/trunk/test/Sema/cxx-namespace.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/cxx-namespace.cpp?rev=53667&r1=53666&r2=53667&view=diff

==============================================================================
--- cfe/trunk/test/Sema/cxx-namespace.cpp (original)
+++ cfe/trunk/test/Sema/cxx-namespace.cpp Wed Jul 16 02:45:46 2008
@@ -14,6 +14,10 @@
 void C(); // expected-error {{error: previous definition is here}}
 namespace C {} // expected-error {{error: redefinition of 'C' as different kind of symbol}}
 
+namespace D {
+  class D {};
+}
+
 namespace S1 {
   int x;
 





More information about the cfe-commits mailing list