summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-07-16 21:01:53 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-07-16 21:01:53 +0000
commitbd25998a45b53aa5d87fcefb41e6b02b75db7edf (patch)
tree7bf35df46ae1902c2712d6fe7efa010faa605a34
parent41cfed7e49b23e2b28f454831c249badba09f855 (diff)
downloadbcm5719-llvm-bd25998a45b53aa5d87fcefb41e6b02b75db7edf.tar.gz
bcm5719-llvm-bd25998a45b53aa5d87fcefb41e6b02b75db7edf.zip
When in C++, make EnumConstant names hide tag names in the same scope, instead of colliding with them.
llvm-svn: 53702
-rw-r--r--clang/lib/Sema/SemaDecl.cpp7
-rw-r--r--clang/test/Sema/class-names.cpp2
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 00c73ea765c..6acbb2d1845 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -2121,7 +2121,12 @@ Sema::DeclTy *Sema::ActOnEnumConstant(Scope *S, DeclTy *theEnumDecl,
// Verify that there isn't already something declared with this name in this
// scope.
if (Decl *PrevDecl = LookupDecl(Id, Decl::IDNS_Ordinary, S)) {
- if (IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
+ // When in C++, we may get a TagDecl with the same name; in this case the
+ // enum constant will 'hide' the tag.
+ assert((getLangOptions().CPlusPlus || !isa<TagDecl>(PrevDecl)) &&
+ "Received TagDecl when not in C++!");
+ if (!isa<TagDecl>(PrevDecl) &&
+ IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
if (isa<EnumConstantDecl>(PrevDecl))
Diag(IdLoc, diag::err_redefinition_of_enumerator, Id->getName());
else
diff --git a/clang/test/Sema/class-names.cpp b/clang/test/Sema/class-names.cpp
index b78d6964e26..2a9cd74c3ba 100644
--- a/clang/test/Sema/class-names.cpp
+++ b/clang/test/Sema/class-names.cpp
@@ -48,3 +48,5 @@ void bar3() {
}
enum E e2;
+
+enum E2 { E2 };
OpenPOWER on IntegriCloud