Commit da9e9b57 by Matthew Beliveau Committed by Matthew Beliveau

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
parent 69352933
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
......
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.
......
......@@ -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;
......
......@@ -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.
......
......@@ -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
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment