[cfe-commits] r53702 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/class-names.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Wed Jul 16 14:01:53 PDT 2008


Author: akirtzidis
Date: Wed Jul 16 16:01:53 2008
New Revision: 53702

URL: http://llvm.org/viewvc/llvm-project?rev=53702&view=rev
Log:
When in C++, make EnumConstant names hide tag names in the same scope, instead of colliding with them.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/class-names.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=53702&r1=53701&r2=53702&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Jul 16 16:01:53 2008
@@ -2121,7 +2121,12 @@
   // 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

Modified: cfe/trunk/test/Sema/class-names.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/class-names.cpp?rev=53702&r1=53701&r2=53702&view=diff

==============================================================================
--- cfe/trunk/test/Sema/class-names.cpp (original)
+++ cfe/trunk/test/Sema/class-names.cpp Wed Jul 16 16:01:53 2008
@@ -48,3 +48,5 @@
 }
 
 enum E e2;
+
+enum E2 { E2 };





More information about the cfe-commits mailing list