]> granicus.if.org Git - clang/commitdiff
When in C++, make EnumConstant names hide tag names in the same scope, instead of...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Jul 2008 21:01:53 +0000 (21:01 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 16 Jul 2008 21:01:53 +0000 (21:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53702 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/class-names.cpp

index 00c73ea765c432759c4044a27469350354af287a..6acbb2d1845ad1cabf12c1ee088f2024901c4cf8 100644 (file)
@@ -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
index b78d6964e260006c876a199cb63b1381094a6fff..2a9cd74c3bac87e8eb05429ffa000d84e3e15316 100644 (file)
@@ -48,3 +48,5 @@ void bar3() {
 }
 
 enum E e2;
+
+enum E2 { E2 };