[cfe-dev] clang++: '-Wswitch-enum' turned on by default

Chris Lattner clattner at apple.com
Thu Sep 16 09:12:09 PDT 2010


On Sep 16, 2010, at 6:42 AM, Douglas Gregor wrote:

> 
> On Sep 16, 2010, at 3:30 AM, Alexandre Colucci wrote:
> 
>> Hey,
>> 
>> I noticed that clang++ seems to always use the option '-Wswitch-enum'. Shouldn't it be turned off by default?
> 
> No, it's an excellent warning to have on by default.
> 
>> Or is there a way to turn it off?
> 
> -Wno-switch-enum

I think that a more serious issue with the warning is that it can produce a *ton* of noise.  In a simple example:

enum x { a, b, c, d, e, f, g };

void foo(enum x a) {
  switch (a) {
  case b:
  case c: break;
  }
}

we produce:

t.c:4:11: warning: enumeration value 'a' not handled in switch [-Wswitch-enum]
  switch (a) {
          ^
t.c:4:11: warning: enumeration value 'd' not handled in switch [-Wswitch-enum]
t.c:4:11: warning: enumeration value 'e' not handled in switch [-Wswitch-enum]
t.c:4:11: warning: enumeration value 'f' not handled in switch [-Wswitch-enum]
t.c:4:11: warning: enumeration value 'g' not handled in switch [-Wswitch-enum]
5 warnings generated.

In this case, I think it would be better to emit one warning say:

t.c:4:11: warning: 5 enumeration values not handled in switch: 'a', 'd', 'e' ... [-Wswitch-enum]

or something like that.  What do you think?

-Chris



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100916/4f493c5f/attachment.html>


More information about the cfe-dev mailing list