[PATCH] D61444: Do not warn on switches over enums that do not use [[maybe_unused]] enumerators

David Blaikie via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 2 09:30:43 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rC359800: Do not warn on switches over enums that do not use [[maybe_unused]] enumerators (authored by dblaikie, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61444?vs=197794&id=197806#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61444/new/

https://reviews.llvm.org/D61444

Files:
  lib/Sema/SemaStmt.cpp
  test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp


Index: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
===================================================================
--- test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
+++ test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
@@ -5,9 +5,17 @@
 
 struct [[maybe_unused]] S {};
 
+enum E1 {
+  EnumVal [[maybe_unused]],
+  UsedEnumVal,
+};
+
 void f() {
   int x; // expected-warning {{unused variable}}
   typedef int I; // expected-warning {{unused typedef 'I'}}
+  E1 e;
+  switch (e) { // expected-warning {{enumeration value 'UsedEnumVal' not handled in switch}}
+  }
 
   // Should not warn about these due to not being used.
   [[maybe_unused]] int y;
@@ -17,10 +25,16 @@
   S s;
   maybe_unused_int test;
   y = 12;
+  switch (e) {
+  case UsedEnumVal:
+    break;
+  }
 }
 
 #ifdef EXT
 // expected-warning at 6 {{use of the 'maybe_unused' attribute is a C++17 extension}}
-// expected-warning at 13 {{use of the 'maybe_unused' attribute is a C++17 extension}}
-// expected-warning at 14 {{use of the 'maybe_unused' attribute is a C++17 extension}}
+// expected-warning at 9 {{use of the 'maybe_unused' attribute is a C++17 extension}}
+// expected-warning at 9 {{attributes on an enumerator declaration are a C++17 extension}}
+// expected-warning at 21 {{use of the 'maybe_unused' attribute is a C++17 extension}}
+// expected-warning at 22 {{use of the 'maybe_unused' attribute is a C++17 extension}}
 #endif
Index: lib/Sema/SemaStmt.cpp
===================================================================
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1162,6 +1162,9 @@
           break;
         }
 
+        if (EI->second->hasAttr<UnusedAttr>())
+          continue;
+
         // Drop unneeded case values
         while (CI != CaseVals.end() && CI->first < EI->first)
           CI++;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61444.197806.patch
Type: text/x-patch
Size: 1793 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190502/55ba0d7d/attachment.bin>


More information about the cfe-commits mailing list