This is the mail archive of the
mailing list for the GCC project.
Re: PATCH RFA: Change -Wswitch behaviour when there is a default case
- From: Andrew Haley <aph at redhat dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc-patches at gcc dot gnu dot org, java-patches at gcc dot gnu dot org
- Date: Sat, 06 Jun 2009 09:24:00 +0100
- Subject: Re: PATCH RFA: Change -Wswitch behaviour when there is a default case
- References: <email@example.com>
Ian Lance Taylor wrote:
> -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
> 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.