Warning : case not evaluated in enumerated type?

I recently upgraded to the new compiler Clang LLVM 4.0 and its nice. Is just in this case it is showing me an ugly warning for some old legacy code:

Warning: case value not in enumerated type 'SomeConstants' (aka 'enum SomeConstants') [-Wswitch]
switch (var) {
    case kConstant: case 3: case 4: case 8: case 35: //WARNING HERE :(
    // do my thing here
    break;
    case kOtherConstant:
    // do another thing here
    break;
    default:
    break;
}

var could be one of the values defined in the enum something like this:

typedef enum SomeConstants {
    kConstant,
    kOtherConstant,
};

and as you see 2, 4, 8, 35 are not defined (that is why the compiler is complining), but in reality they happen (this is one the obscure parts of this closed source library I am using).

Is there a way I can somehow modify my switch code so I don't get the harmless but annoying warning? Right now I am silencing it using:

switch (var) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch"
    case kConstant: case 3: case 4: case 8: case 35:
#pragma GCC diagnostic pop
    ...

I wonder if there is a more elegant way of solving this.

Answers


You can cast the expression of the switch() statement to int so it doesn't/can't perform that check.

After all, it's actually being used to hold an int value, not one of the listed enumerators.


Need Your Help

Google Maps v3 InfoBox Event Propagation in Mobile Safari

javascript google-maps javascript-events safari mobile-safari

I have created an infobox using google maps api v3 and infoBox from the maps utility library . The infobox has overflow-y data. Scrolling works exactly as expected on IE, FF, Chrome and Safari de...