re PR c++/90590 (enumeration value not handled in switch warning for std::ios_base...
authorMatthew Beliveau <mbelivea@redhat.com>
Thu, 1 Aug 2019 18:04:23 +0000 (18:04 +0000)
committerMatthew Beliveau <mbelivea@gcc.gnu.org>
Thu, 1 Aug 2019 18:04:23 +0000 (18:04 +0000)
PR c++/90590

* c-warn.c (c_do_switch_warnings): Suppress warning for enumerators
with reserved names that are in a system header.

* c-c++-common/pr90590-1.c: New test.
* c-c++-common/pr90590-1.h: New test.
* c-c++-common/pr90590-2.c: New test.
* c-c++-common/pr90590-2.h: New test.

From-SVN: r273980

gcc/ChangeLog
gcc/c-family/c-warn.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr90590-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr90590-1.h [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr90590-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr90590-2.h [new file with mode: 0644]

index 0acaa7b66b9089c7461b0aefaa4d506b8e2934b5..dc06ef4694349e46c73d164a1364a34c4b81a24a 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-01  Matthew Beliveau  <mbelivea@redhat.com>
+
+       PR c++/90590
+       * c-warn.c (c_do_switch_warnings): Suppress warning for enumerators
+       with reserved names that are in a system header.
+
 2019-08-01  Uroš Bizjak  <ubizjak@gmail.com>
 
        * config/i386/mmx.md (vec_extractv2si_0): Add (r,x) alternative.
index b5d09e761d73e9b24fe33fa54dccbd0b128e8a6c..d671b77a2b06295cd3a7bed7044c9e71a129bd98 100644 (file)
@@ -34,6 +34,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gcc-rich-location.h"
 #include "gimplify.h"
 #include "c-family/c-indentation.h"
+#include "c-family/c-spellcheck.h"
 #include "calls.h"
 #include "stor-layout.h"
 
@@ -1628,6 +1629,15 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
       if (cond && tree_int_cst_compare (cond, value))
        continue;
 
+      /* If the enumerator is defined in a system header and uses a reserved
+        name, then we continue to avoid throwing a warning.  */
+      location_t loc = DECL_SOURCE_LOCATION
+           (TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type)));
+      if (in_system_header_at (loc)
+         && name_reserved_for_implementation_p
+             (IDENTIFIER_POINTER (TREE_PURPOSE (chain))))
+       continue;
+
       /* If there is a default_node, the only relevant option is
         Wswitch-enum.  Otherwise, if both are enabled then we prefer
         to warn using -Wswitch because -Wswitch is enabled by -Wall
index d16e123d61a7ad29386721b4df81778d71647254..6b363ac3e0be62d5d710dbe1f31db5e222129ba2 100644 (file)
@@ -1,3 +1,11 @@
+2019-08-01  Matthew Beliveau  <mbelivea@redhat.com>
+
+       PR c++/90590
+       * c-c++-common/pr90590-1.c: New test.
+       * c-c++-common/pr90590-1.h: New test.
+       * c-c++-common/pr90590-2.c: New test.
+       * c-c++-common/pr90590-2.h: New test.
+
 2019-08-01  Marek Polacek  <polacek@redhat.com>
 
        PR c++/90805 - detect narrowing in case values.
diff --git a/gcc/testsuite/c-c++-common/pr90590-1.c b/gcc/testsuite/c-c++-common/pr90590-1.c
new file mode 100644 (file)
index 0000000..4e11deb
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/90590
+// { dg-options -Wswitch }
+#include "pr90590-1.h"
+
+void
+g ()
+{
+  enum E e = _A;
+  switch (e) // { dg-bogus "enumeration value '_C' not handled in switch" }
+    {
+    case _A:
+    case _B:
+      break;
+    }
+}
diff --git a/gcc/testsuite/c-c++-common/pr90590-1.h b/gcc/testsuite/c-c++-common/pr90590-1.h
new file mode 100644 (file)
index 0000000..22f1a7d
--- /dev/null
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+enum E { _A, _B, _C };
diff --git a/gcc/testsuite/c-c++-common/pr90590-2.c b/gcc/testsuite/c-c++-common/pr90590-2.c
new file mode 100644 (file)
index 0000000..23da97f
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/90590
+// { dg-options -Wswitch }
+
+#include "pr90590-2.h"
+
+void
+fn ()
+{
+  switch (c.b) // { dg-bogus "enumeration value" }
+    ;
+}
diff --git a/gcc/testsuite/c-c++-common/pr90590-2.h b/gcc/testsuite/c-c++-common/pr90590-2.h
new file mode 100644 (file)
index 0000000..e4f8635
--- /dev/null
@@ -0,0 +1,4 @@
+#pragma GCC system_header
+struct {
+  enum { _A } b;
+} c;