[cfe-dev] Question on -Wswitch-enum

David Chisnall csdavec at swan.ac.uk
Fri Aug 3 03:39:26 PDT 2012


In clang head, your test program generates no warnings, and removing the default: case introduces one, just as you propose.

Apple's random-snapshot-from-head-some-time-in-the-past most likely contains a bug.  

David

On 3 Aug 2012, at 10:43, Nicola Gigante wrote:

> Hello.
> 
> After switching to the clang shipped with Xcode 4.4,
> new warnings appeared in my previously "warnings-free" codebase.
> 
> This is an example code:
> enum Enum {
>   First,
>   Second,
>   Third,
>   Fourth
> };
> 
> int func(Enum e);
> 
> int func(Enum e)
> {
>   switch(e)
>   {
>      case First:
>         return 42;
>      case Second:
>         return 84;
>      default:
>         return 0;
>   }
> }
> 
> Compiling with -Weverything I get this warning:
> prova.cpp:13:11: warning: enumeration values 'Third' and 'Fourth' not explicitly handled in switch [-Wswitch-enum]
>   switch(e)
> 
> In my opinion, the presence of the default: label in the switch statement should silence this warning,
> because those enumeration values are actually handled. It's not like something like this:
> switch(e)
> {
>   case First:
>      return 42;
>   case Second:
>      return 84;
> }
> 
> where the developer could have forgotten to handle all the cases.
> This warning is causing a lot of noise in my project, where i have enums with dozens of enum values and
> to silence this warning I have to replicate 70 case labels in every switch statement, while silencing this warning
> with -Wno-switch-enum would make it disappear also for really wrong cases like the last snippet above.
> 
> So I would like to know if this is intentional, and if so what is the rationale behind this behaviour.
> 
> Thank you,
> 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