summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaDecl.cpp13
-rw-r--r--clang/test/Sema/cxx-namespace.cpp4
2 files changed, 12 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4836be4b8ef..f4d9da60147 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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;
+ }
}
}
diff --git a/clang/test/Sema/cxx-namespace.cpp b/clang/test/Sema/cxx-namespace.cpp
index df0fa253ef5..62251d3535e 100644
--- a/clang/test/Sema/cxx-namespace.cpp
+++ b/clang/test/Sema/cxx-namespace.cpp
@@ -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;
OpenPOWER on IntegriCloud