From: Argyrios Kyrtzidis Date: Wed, 16 Jul 2008 21:01:53 +0000 (+0000) Subject: When in C++, make EnumConstant names hide tag names in the same scope, instead of... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ff12f078c70acad7ef18cb4906d17a203d2267a;p=clang When in C++, make EnumConstant names hide tag names in the same scope, instead of colliding with them. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53702 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 00c73ea765..6acbb2d184 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/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(PrevDecl)) && + "Received TagDecl when not in C++!"); + if (!isa(PrevDecl) && + IdResolver.isDeclInScope(PrevDecl, CurContext, S)) { if (isa(PrevDecl)) Diag(IdLoc, diag::err_redefinition_of_enumerator, Id->getName()); else diff --git a/test/Sema/class-names.cpp b/test/Sema/class-names.cpp index b78d6964e2..2a9cd74c3b 100644 --- a/test/Sema/class-names.cpp +++ b/test/Sema/class-names.cpp @@ -48,3 +48,5 @@ void bar3() { } enum E e2; + +enum E2 { E2 };