I noticed that clang++ seems to always use the option '-Wswitch-enum'. Shouldn't it be turned off by default? Or is there a way to turn it off?
My projects contain a lot of files. When I compile them with clang++, I get thousands of "Enumeration value 'xxx' not handled in switch" warnings .
I would like to avoid to fix all these warnings. This issue also occurs with Xcode 4.0b3.
I filed the bug 8164.
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
My projects contain a lot of files. When I compile them with clang++, I get thousands of "Enumeration value 'xxx' not handled in switch" warnings .
I would like to avoid to fix all these warnings. This issue also occurs with Xcode 4.0b3.
I filed the bug 8164.
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]
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?
That would be sweet IMHO. Many of the open source libs I use generate
tonnes of noise with this warning, and your proposed change would force
attention on the switch itself and not each little missing case.