PATCH RFA: Change -Wswitch behaviour when there is a default case

Ian Lance Taylor iant@google.com
Fri Jun 5 23:07:00 GMT 2009


-Wswitch issues two warnings about switches on values of enum type.
First, it warns if the switch omits any value of the enum type.  Second,
it warns if the switch includes any value which is not of the enum type.

Currently, both warnings are disabled if the switch has a default case.
This does not make sense.  It makes sense to disable the first warning
if the switch has a default label.  However, it does not make sense to
disable the second warning.  A case statement using a value which is not
of the enum type does not make more sense because there is a default
case.

I think the current gcc behaviour is simply a historical legacy of how
the code happened to work.  I can't think of any good reason for it to
work this way.  Therefore, I propose that we change it.

The first patch changes the behaviour of -Wswitch.  This patch requires
approval from the C or C++ frontend maintainers.

The second patch fixes the two cases in the gcc sources for which the
first patch gives new warnings.  This patch requires approval from the
Java frontend maintainers.  I could have simply used casts in the switch
statements, but I applied what I thought would be better fixes.

Bootstrapped and tested on x86_64-unknown-linux-gnu.  OK for mainline?

Ian

gcc/ChangeLog:

2009-06-05  Ian Lance Taylor  <iant@google.com>

	* dwarf2.h (enum dwarf_location_atom): Add
	INTERNAL_DW_OP_tls_addr.
	* dwarf2out.c (INTERNAL_DW_OP_tls_addr): Don't #define.

	* c-common.c (c_do_switch_warnings): Don't exit early for -Wswitch
	with no default node.  Change warning with %H to warning_at.
	Don't clear warn_switch around case checking.
	* doc/invoke.texi (Warning Options): Clarify distinction between
	-Wswitch and -Wswitch-enum.

gcc/testsuite/ChangeLog:

2009-06-05  Ian Lance Taylor  <iant@google.com>

	* g++.dg/warn/Wswitch-3.C: New testcase.
	* gcc.dg/Wswitch.c: Adjust for -Wswitch change.
	* gcc.dg/Wswitch-enum-error.c: Likewise.
	* gcc.dg/Wswitch-error.c: Likewise.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo1.patch
Type: text/x-patch
Size: 6701 bytes
Desc: Warn about non-enum case even if there is a default
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20090605/424d58c8/attachment.bin>
-------------- next part --------------


==================================================

gcc/ChangeLog:

2009-06-05  Ian Lance Taylor  <iant@google.com>

	* dwarf2.h (enum dwarf_location_atom): Add
	INTERNAL_DW_OP_tls_addr.
	* dwarf2out.c (INTERNAL_DW_OP_tls_addr): Don't #define.

gcc/java/ChangeLog:

2009-06-05  Ian Lance Taylor  <iant@google.com>

	* jcf-parse.c (handle_constant): Change local variable 'kind' to
	unsigned int.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-patch
Size: 2428 bytes
Desc: Fix new warnings
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20090605/424d58c8/attachment-0001.bin>


More information about the Java-patches mailing list