From: Aaron Ballman Date: Mon, 22 Oct 2018 13:05:53 +0000 (+0000) Subject: Silence the -Wshadow warning for enumerators shadowing a type. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5485eacd4d58c1cbd19ce63c7a737b9d8b667c6b;p=clang Silence the -Wshadow warning for enumerators shadowing a type. Amends r344259 so that enumerators shadowing types are not diagnosed, as shadowing under those circumstances is rarely (if ever) an issue in practice. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344898 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 95623ef100..ef17f8d57b 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -16295,7 +16295,7 @@ Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, Decl *lastEnumConst, return nullptr; if (PrevDecl) { - if (!TheEnumDecl->isScoped()) { + if (!TheEnumDecl->isScoped() && isa(PrevDecl)) { // Check for other kinds of shadowing not already handled. CheckShadow(New, PrevDecl, R); } diff --git a/test/Sema/warn-shadow.c b/test/Sema/warn-shadow.c index 8d1d0aed69..aa8505b0c9 100644 --- a/test/Sema/warn-shadow.c +++ b/test/Sema/warn-shadow.c @@ -64,3 +64,10 @@ enum PR24718_1{pr24718}; // expected-note {{previous declaration is here}} void PR24718(void) { enum PR24718_2{pr24718}; // expected-warning {{declaration shadows a variable in the global scope}} } + +struct PR24718_3; +struct PR24718_4 { + enum { + PR24718_3 // Does not shadow a type. + }; +}; diff --git a/test/SemaCXX/warn-shadow.cpp b/test/SemaCXX/warn-shadow.cpp index e4ad352788..33203f018c 100644 --- a/test/SemaCXX/warn-shadow.cpp +++ b/test/SemaCXX/warn-shadow.cpp @@ -225,3 +225,10 @@ void f(int a) { int PR24718; enum class X { PR24718 }; // Ok, not shadowing + +struct PR24718_1; +struct PR24718_2 { + enum { + PR24718_1 // Does not shadow a type. + }; +};