aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-07-16 07:45:46 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-07-16 07:45:46 +0000
commitb02ef242c76f718a33ec3d9e42f9dbabaf5856b9 (patch)
tree2293dc4334aa9c26795fa78532ca27c037ceab1b
parentd7464be9829a0a8557636a14d17dd9d56594b911 (diff)
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
-rw-r--r--lib/Sema/SemaDecl.cpp13
-rw-r--r--test/Sema/cxx-namespace.cpp4
2 files changed, 12 insertions, 5 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 4836be4b8e..f4d9da6014 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/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/test/Sema/cxx-namespace.cpp b/test/Sema/cxx-namespace.cpp
index df0fa253ef..62251d3535 100644
--- a/test/Sema/cxx-namespace.cpp
+++ b/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;