[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
This commit is contained in:
Andrew Cagney 2002-03-23 16:33:44 +00:00 committed by Andrew Cagney
parent c677cd7f47
commit d6961341dd
9 changed files with 110 additions and 4 deletions

View File

@ -1,3 +1,16 @@
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>
* real.h (N): Special case 128 bit doubles.

View File

@ -228,7 +228,7 @@ in the following sections.
-Wno-import -Wpacked -Wpadded @gol
-Wparentheses -Wpointer-arith -Wredundant-decls @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
-Wunknown-pragmas -Wunreachable-code @gol
-Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol
@ -2034,6 +2034,11 @@ enumeration. (The presence of a @code{default} label prevents this
warning.) @code{case} labels outside the enumeration range also
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
@opindex Wtrigraphs
Warn if any trigraphs are encountered that might change the meaning of

View File

@ -1,3 +1,7 @@
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>
* cp-tree.h (pushdecl, pushlevel, poplevel, set_block,

View File

@ -1356,6 +1356,9 @@ Some of these have no effect when compiling programs written in Fortran:
@cindex -Wswitch option
@cindex options, -Wswitch
@item -Wswitch
@cindex -Wswitch-default option
@cindex options, -Wswitch-default
@item -Wswitch-default
@cindex -Wtraditional option
@cindex options, -Wtraditional
@item -Wtraditional

View File

@ -126,10 +126,15 @@ extern int warn_unknown_pragmas;
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;
/* 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
or that use a null return and have a return-type other than void. */

View File

@ -5284,6 +5284,9 @@ expand_end_case_type (orig_index, orig_type)
&& TREE_CODE (index_expr) != INTEGER_CST)
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,
after the body of the switch. */
if (thiscase->data.case_stmt.default_label == 0)

View File

@ -1,3 +1,7 @@
2002-03-23 Andrew Cagney <ac131313@redhat.com>
* gcc.dg/Wswitch-default.c: New test.
2002-03-23 Jakub Jelinek <jakub@redhat.com>
* g++.dg/other/enum1.C: New test.

View File

@ -0,0 +1,62 @@
/* { 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;
}

View File

@ -1395,10 +1395,15 @@ int warn_uninitialized;
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;
/* 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
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[] =
{"shadow", &warn_shadow, 1,
N_("Warn when one local variable shadows another") },
{"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,
N_("Warn about returning structures, unions or arrays") },
{"cast-align", &warn_cast_align, 1,