This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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
> 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.

OK.

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]