]> granicus.if.org Git - clang/commitdiff
When checking for name collision between a tag and a previously defined namespace...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Jul 2008 07:45:46 +0000 (07:45 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Jul 2008 07:45:46 +0000 (07:45 +0000)
Fix it by taking into account the scope when checking for namespace-tag name collisions.

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

lib/Sema/SemaDecl.cpp
test/Sema/cxx-namespace.cpp

index 4836be4b8efb77afa3bf148eea7f8a5cb91f8b47..f4d9da60147a749b9f037260e83a506fd6804fad 100644 (file)
@@ -1733,11 +1733,14 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagType, TagKind TK,
       // 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;
+      }
     }
   }
   
index df0fa253ef5cca87c9ca71b406690f543f8a8d8c..62251d3535e425ec96295fcdee84af5057cba9f3 100644 (file)
@@ -14,6 +14,10 @@ namespace B {} // expected-error {{error: redefinition of 'B' as different kind
 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;