aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Beliveau <mbelivea@redhat.com>2019-06-21 17:50:29 +0000
committerMatthew Beliveau <mbelivea@gcc.gnu.org>2019-06-21 17:50:29 +0000
commitda9e9b571483537a617d08ce7f0da84435497053 (patch)
tree55976f753683551efc49e3f8a7d93717cf059d6b
parent69352933301e0f67078fff8404b1eeb5c14d6b60 (diff)
downloadgcc-da9e9b571483537a617d08ce7f0da84435497053.zip
gcc-da9e9b571483537a617d08ce7f0da84435497053.tar.gz
gcc-da9e9b571483537a617d08ce7f0da84435497053.tar.bz2
PR c++/90875 - added -Wswitch-outside-range option
* 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
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-warn.c15
-rw-r--r--gcc/c-family/c.opt4
-rw-r--r--gcc/doc/invoke.texi7
-rw-r--r--gcc/testsuite/ChangeLog8
6 files changed, 38 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index fa45d9d..14fb81a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index c1522b2..fec706a 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -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.
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 5941c10..b5d09e7 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -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;
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 572cf18..a4cf3bd 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -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.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index eaef4cd..4f93c7e 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9826e3d..2c80ac4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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