Commit d6961341 by Andrew Cagney Committed by Andrew Cagney

[multiple changes]

2002-03-23  Andrew Cagney  <ac131313@redhat.com>

	* doc/invoke.texi (Option Summary): Mention -Wswitch-default.
	(Warning Options): Document -Wswitch-default.
	* toplev.c (W_options): Add -Wswitch-default.  Update comment on
	-Wswitch.
	(warn_switch_default): Define variable.
	(warn_switch): Update comment.
	* flags.h (warn_switch_default): Declare variable.
	(warn_switch): Update comment.
	* stmt.c (expand_end_case): Check for and, when
	warn_switch_no_default, warn of a missing default case.

Index: f/ChangeLog
Sat Mar 23 11:18:17 2002  Andrew Cagney  <ac131313@redhat.com>

	* invoke.texi (Warning Options): Mention -Wswitch-default.

Index: testsuite/ChangeLog
2002-03-23  Andrew Cagney  <ac131313@redhat.com>

	* gcc.dg/Wswitch-default.c: New test.

From-SVN: r51238
parent c677cd7f
2002-03-23 Andrew Cagney <ac131313@redhat.com>
* doc/invoke.texi (Option Summary): Mention -Wswitch-default.
(Warning Options): Document -Wswitch-default.
* toplev.c (W_options): Add -Wswitch-default. Update comment on
-Wswitch.
(warn_switch_default): Define variable.
(warn_switch): Update comment.
* flags.h (warn_switch_default): Declare variable.
(warn_switch): Update comment.
* stmt.c (expand_end_case): Check for and, when
warn_switch_no_default, warn of a missing default case.
2002-03-23 Alan Modra <amodra@bigpond.net.au> 2002-03-23 Alan Modra <amodra@bigpond.net.au>
* real.h (N): Special case 128 bit doubles. * real.h (N): Special case 128 bit doubles.
......
...@@ -228,7 +228,7 @@ in the following sections. ...@@ -228,7 +228,7 @@ in the following sections.
-Wno-import -Wpacked -Wpadded @gol -Wno-import -Wpacked -Wpadded @gol
-Wparentheses -Wpointer-arith -Wredundant-decls @gol -Wparentheses -Wpointer-arith -Wredundant-decls @gol
-Wreturn-type -Wsequence-point -Wshadow @gol -Wreturn-type -Wsequence-point -Wshadow @gol
-Wsign-compare -Wswitch -Wsystem-headers @gol -Wsign-compare -Wswitch -Wswitch-default -Wsystem-headers @gol
-Wtrigraphs -Wundef -Wuninitialized @gol -Wtrigraphs -Wundef -Wuninitialized @gol
-Wunknown-pragmas -Wunreachable-code @gol -Wunknown-pragmas -Wunreachable-code @gol
-Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol -Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol
...@@ -2034,6 +2034,11 @@ enumeration. (The presence of a @code{default} label prevents this ...@@ -2034,6 +2034,11 @@ enumeration. (The presence of a @code{default} label prevents this
warning.) @code{case} labels outside the enumeration range also warning.) @code{case} labels outside the enumeration range also
provoke warnings when this option is used. provoke warnings when this option is used.
@item -Wswitch-default
@opindex Wswitch-switch
Warn whenever a @code{switch} statement does not have a @code{default}
case.
@item -Wtrigraphs @item -Wtrigraphs
@opindex Wtrigraphs @opindex Wtrigraphs
Warn if any trigraphs are encountered that might change the meaning of Warn if any trigraphs are encountered that might change the meaning of
......
Sat Mar 23 11:18:17 2002 Andrew Cagney <ac131313@redhat.com>
* invoke.texi (Warning Options): Mention -Wswitch-default.
Thu Mar 21 18:55:41 2002 Neil Booth <neil@daikokuya.demon.co.uk> Thu Mar 21 18:55:41 2002 Neil Booth <neil@daikokuya.demon.co.uk>
* cp-tree.h (pushdecl, pushlevel, poplevel, set_block, * cp-tree.h (pushdecl, pushlevel, poplevel, set_block,
......
...@@ -1356,6 +1356,9 @@ Some of these have no effect when compiling programs written in Fortran: ...@@ -1356,6 +1356,9 @@ Some of these have no effect when compiling programs written in Fortran:
@cindex -Wswitch option @cindex -Wswitch option
@cindex options, -Wswitch @cindex options, -Wswitch
@item -Wswitch @item -Wswitch
@cindex -Wswitch-default option
@cindex options, -Wswitch-default
@item -Wswitch-default
@cindex -Wtraditional option @cindex -Wtraditional option
@cindex options, -Wtraditional @cindex options, -Wtraditional
@item -Wtraditional @item -Wtraditional
......
...@@ -126,10 +126,15 @@ extern int warn_unknown_pragmas; ...@@ -126,10 +126,15 @@ extern int warn_unknown_pragmas;
extern int warn_shadow; extern int warn_shadow;
/* Warn if a switch on an enum fails to have a case for every enum value. */ /* Warn if a switch on an enum, that does not have a default case,
fails to have a case for every enum value. */
extern int warn_switch; extern int warn_switch;
/* Warn if a switch does not have a default case. */
extern int warn_switch_default;
/* Nonzero means warn about function definitions that default the return type /* Nonzero means warn about function definitions that default the return type
or that use a null return and have a return-type other than void. */ or that use a null return and have a return-type other than void. */
......
...@@ -5284,6 +5284,9 @@ expand_end_case_type (orig_index, orig_type) ...@@ -5284,6 +5284,9 @@ expand_end_case_type (orig_index, orig_type)
&& TREE_CODE (index_expr) != INTEGER_CST) && TREE_CODE (index_expr) != INTEGER_CST)
check_for_full_enumeration_handling (orig_type); check_for_full_enumeration_handling (orig_type);
if (warn_switch_default && !thiscase->data.case_stmt.default_label)
warning ("switch missing default case");
/* If we don't have a default-label, create one here, /* If we don't have a default-label, create one here,
after the body of the switch. */ after the body of the switch. */
if (thiscase->data.case_stmt.default_label == 0) if (thiscase->data.case_stmt.default_label == 0)
......
2002-03-23 Andrew Cagney <ac131313@redhat.com>
* gcc.dg/Wswitch-default.c: New test.
2002-03-23 Jakub Jelinek <jakub@redhat.com> 2002-03-23 Jakub Jelinek <jakub@redhat.com>
* g++.dg/other/enum1.C: New test. * g++.dg/other/enum1.C: New test.
......
/* { dg-do compile } */
/* { dg-options "-Wswitch-default" } */
enum e { e1, e2 };
int
foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el,
enum e em, enum e en, enum e eo, enum e ep)
{
switch (i)
{
case 1: return 1;
case 2: return 2;
} /* { dg-warning "switch missing default case" } */
switch (j)
{
case 3: return 4;
case 4: return 3;
default: break;
}
switch (ei)
{ /* { dg-warning "switch missing default case" } */
}
switch (ej)
{
default: break;
}
switch (ek)
{
case e1: return 1;
} /* { dg-warning "switch missing default case" } */
switch (el)
{
case e1: return 1;
default: break;
}
switch (em)
{
case e1: return 1;
case e2: return 2;
} /* { dg-warning "switch missing default case" } */
switch (en)
{
case e1: return 1;
case e2: return 2;
default: break;
}
switch (eo)
{
case e1: return 1;
case e2: return 2;
case 3: return 3;
} /* { dg-warning "switch missing default case" } */
switch (ep)
{
case e1: return 1;
case e2: return 2;
case 3: return 3;
default: break;
}
return 0;
}
...@@ -1395,10 +1395,15 @@ int warn_uninitialized; ...@@ -1395,10 +1395,15 @@ int warn_uninitialized;
int warn_shadow; int warn_shadow;
/* Warn if a switch on an enum fails to have a case for every enum value. */ /* Warn if a switch on an enum, that does not have a default case,
fails to have a case for every enum value. */
int warn_switch; int warn_switch;
/* Warn if a switch does not have a default case. */
int warn_switch_default;
/* Nonzero means warn about function definitions that default the return type /* Nonzero means warn about function definitions that default the return type
or that use a null return and have a return-type other than void. */ or that use a null return and have a return-type other than void. */
...@@ -1468,7 +1473,9 @@ static const lang_independent_options W_options[] = ...@@ -1468,7 +1473,9 @@ static const lang_independent_options W_options[] =
{"shadow", &warn_shadow, 1, {"shadow", &warn_shadow, 1,
N_("Warn when one local variable shadows another") }, N_("Warn when one local variable shadows another") },
{"switch", &warn_switch, 1, {"switch", &warn_switch, 1,
N_("Warn about enumerated switches missing a specific case") }, N_("Warn about enumerated switches, with no default, missing a case") },
{"switch-default", &warn_switch_default, 1,
N_("Warn about enumerated switches missing a default case") },
{"aggregate-return", &warn_aggregate_return, 1, {"aggregate-return", &warn_aggregate_return, 1,
N_("Warn about returning structures, unions or arrays") }, N_("Warn about returning structures, unions or arrays") },
{"cast-align", &warn_cast_align, 1, {"cast-align", &warn_cast_align, 1,
......
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