]> granicus.if.org Git - clang/commitdiff
Silence the -Wshadow warning for enumerators shadowing a type.
authorAaron Ballman <aaron@aaronballman.com>
Mon, 22 Oct 2018 13:05:53 +0000 (13:05 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 22 Oct 2018 13:05:53 +0000 (13:05 +0000)
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

lib/Sema/SemaDecl.cpp
test/Sema/warn-shadow.c
test/SemaCXX/warn-shadow.cpp

index 95623ef100f85b941b2be59f650933412c1db324..ef17f8d57b99d844f3a221f5366d88a9a0b6ee83 100644 (file)
@@ -16295,7 +16295,7 @@ Decl *Sema::ActOnEnumConstant(Scope *S, Decl *theEnumDecl, Decl *lastEnumConst,
     return nullptr;
 
   if (PrevDecl) {
-    if (!TheEnumDecl->isScoped()) {
+    if (!TheEnumDecl->isScoped() && isa<ValueDecl>(PrevDecl)) {
       // Check for other kinds of shadowing not already handled.
       CheckShadow(New, PrevDecl, R);
     }
index 8d1d0aed693f0c92479f54de0190d5a9c41c19e0..aa8505b0c91724534a91445b58e8411dffb68aeb 100644 (file)
@@ -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.
+  };
+};
index e4ad352788a6e7837d9db9991f4ad5a6ee8d1029..33203f018c85defc8ede69e7df69faa85ddfe4d9 100644 (file)
@@ -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.
+  };
+};