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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53667 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 4836be4..f4d9da6 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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;
+      }
     }
   }