]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/90875 - added -Wswitch-outside-range option
authorMatthew Beliveau <mbelivea@redhat.com>
Fri, 21 Jun 2019 17:50:29 +0000 (17:50 +0000)
committerMatthew Beliveau <mbelivea@gcc.gnu.org>
Fri, 21 Jun 2019 17:50:29 +0000 (17:50 +0000)
* doc/invoke.texi (Wswitch-outside-range): Document.

* c.opt (Wswitch-outside-range): Added new option.
* c-warn.c (c_do_switch_warnings): Use OPT_Wswitch-outside-range.

* c-c++-common/Wswitch-outside-range-1.c: New test.
* c-c++-common/Wswitch-outside-range-2.c: New test.
* c-c++-common/Wswitch-outside-range-3.c: New test.
* c-c++-common/Wswitch-outside-range-4.c: New test.

From-SVN: r272559

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-warn.c
gcc/c-family/c.opt
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog

index fa45d9d2185f23efee6281b4b169618f9c978d6d..14fb81a6de3e0b994bdf138dfd2fcc359b35a575 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-21  Matthew Beliveau  <mbelivea@redhat.com>
+
+       PR c++/90875 - added -Wswitch-outside-range option
+       * doc/invoke.texi (Wswitch-outside-range): Document.
+
 2019-06-21  Jeff Law  <law@redhat.com>
 
        PR tree-optimization/90949
index c1522b249b547829de2ba3e1a932d953e1693eca..fec706ae94ce2507eaa4b61d23c3c528808e04c7 100644 (file)
@@ -1,3 +1,9 @@
+2019-06-21  Matthew Beliveau  <mbelivea@redhat.com>
+
+       PR c++/90875 - added -Wswitch-outside-range option
+       * c.opt (Wswitch-outside-range): Added new option.
+       * c-warn.c (c_do_switch_warnings): Use OPT_Wswitch-outside-range.
+
 2019-06-21  Marek Polacek  <polacek@redhat.com>
 
        PR c++/90953 - ICE with -Wmissing-format-attribute.
index 5941c10cddb63ec55bcf99a8afdbbbd96ec03279..b5d09e761d73e9b24fe33fa54dccbd0b128e8a6c 100644 (file)
@@ -1460,8 +1460,9 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
                                       min_value) >= 0)
            {
              location_t loc = EXPR_LOCATION ((tree) node->value);
-             warning_at (loc, 0, "lower value in case label range"
-                                 " less than minimum value for type");
+             warning_at (loc, OPT_Wswitch_outside_range,
+                         "lower value in case label range less than minimum"
+                         " value for type");
              CASE_LOW ((tree) node->value) = convert (TREE_TYPE (cond),
                                                       min_value);
              node->key = (splay_tree_key) CASE_LOW ((tree) node->value);
@@ -1474,8 +1475,8 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
              if (node == NULL || !node->key)
                break;
              location_t loc = EXPR_LOCATION ((tree) node->value);
-             warning_at (loc, 0, "case label value is less than minimum "
-                                 "value for type");
+             warning_at (loc, OPT_Wswitch_outside_range, "case label value is"
+                         " less than minimum value for type");
              splay_tree_remove (cases, node->key);
            }
          while (1);
@@ -1491,8 +1492,8 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
                                   max_value) > 0)
        {
          location_t loc = EXPR_LOCATION ((tree) node->value);
-         warning_at (loc, 0, "upper value in case label range"
-                             " exceeds maximum value for type");
+         warning_at (loc, OPT_Wswitch_outside_range, "upper value in case"
+                     " label range exceeds maximum value for type");
          CASE_HIGH ((tree) node->value)
            = convert (TREE_TYPE (cond), max_value);
          outside_range_p = true;
@@ -1503,7 +1504,7 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
             != NULL)
        {
          location_t loc = EXPR_LOCATION ((tree) node->value);
-         warning_at (loc, 0,
+         warning_at (loc, OPT_Wswitch_outside_range,
                      "case label value exceeds maximum value for type");
          splay_tree_remove (cases, node->key);
          outside_range_p = true;
index 572cf1862629b676bd7b2987d61ce7b65c89cefb..a4cf3bd623d6b80bcf7957e290423c6c389eb61c 100644 (file)
@@ -819,6 +819,10 @@ Wswitch-bool
 C ObjC C++ ObjC++ Var(warn_switch_bool) Warning Init(1)
 Warn about switches with boolean controlling expression.
 
+Wswitch-outside-range
+C ObjC C++ ObjC++ Var(warn_switch_outside_range) Warning Init(1)
+Warn about switch values that are outside of the switch's type range.
+
 Wtemplates
 C++ ObjC++ Var(warn_templates) Warning
 Warn on primary template declaration.
index eaef4cd63d282be7fcd624222d650e4e67f28416..4f93c7e0de73d1978a33053dfc42237671da834e 100644 (file)
@@ -5390,6 +5390,13 @@ switch ((int) (a == 4))
 @end smallexample
 This warning is enabled by default for C and C++ programs.
 
+@item -Wswitch-outside-range
+@opindex Wswitch-outside-range
+@opindex Wno-switch-outside-range
+Warn whenever a @code{switch} case has a value that is outside of its
+respective type range.  This warning is enabled by default for
+C and C++ programs.
+
 @item -Wswitch-unreachable
 @opindex Wswitch-unreachable
 @opindex Wno-switch-unreachable
index 9826e3de00262594f5d3a6c276a676852d82e9d3..2c80ac4bdd6b8d9855dc6adb018a125cc9f00fc8 100644 (file)
@@ -1,3 +1,11 @@
+2019-06-21  Matthew Beliveau  <mbelivea@redhat.com>
+
+       PR c++/90875 - added -Wswitch-outside-range option
+       * c-c++-common/Wswitch-outside-range-1.c: New test.
+       * c-c++-common/Wswitch-outside-range-2.c: New test.
+       * c-c++-common/Wswitch-outside-range-3.c: New test.
+       * c-c++-common/Wswitch-outside-range-4.c: New test.
+
 2019-06-21  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/51991