[cfe-dev] Question on -Wswitch-enum

Anton Staaf anton at socialhacker.com
Fri Aug 3 12:37:27 PDT 2012


On Fri, Aug 3, 2012 at 11:40 AM, Nicola Gigante
<nicola.gigante at gmail.com> wrote:
>
> Il giorno 03/ago/2012, alle ore 20:22, John Wiegley ha scritto:
>
>
> I actually opened a bug on this behavior, it was counter-intuitive to me as
> well.  The resolution was that it's not always desirable to make
> -Weverything
> compile silently.  You need to add a few -Won- directives as well.

The behavior of -Wswitch-enum is actually very useful in some code
bases.  In particular it can be nice when you use an enum for a list
of states in an embedded system.  You simultaneously want to be able
to warn if you don't handle a state in a switch and you also want to
be able to have a default catch invalid states.  If the default
disabled the check that all enumerated values are present as cases it
would be possible to add a new state to the enum and forget to add it
to one of the switches.

-Anton

>
> Yes, having -Weverything compile silently is nearly impossible, I already
> have some -Wno-* flags in the compilation flags, but I add them carefully.
> Anyway, I didn't know about the difference between -Wswitch and
> -Wswitch-enum,
> so It's ok after all.
>
> Thanks,
> Nicola
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>



More information about the cfe-dev mailing list