[cfe-dev] clang++: '-Wswitch-enum' turned on by default
Douglas Gregor
dgregor at apple.com
Thu Sep 16 09:27:23 PDT 2010
On Sep 16, 2010, at 9:12 AM, Chris Lattner wrote:
>
> 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?
I think that's an excellent idea.
- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100916/29d16fd9/attachment.html>
More information about the cfe-dev
mailing list