If a switch with an argument of type enumeration skips some constants and does not have a default branch, the gcc -Wswitch option raises a warning similar to
warning: enumeration value 'WHATEVER' not handled in switch
However, many of our switches are similar to:
enum foo { FOO_ONE, FOO_TWO, FOO_COUNT };
where FOO_COUNT is never displayed as a value, but is used to determine the number of values that are defined and can be displayed in a variable. Since we are indexing an array with an enumeration value or bit packing, and you need to check that it will match or something like that. Thus, an enumeration that processes all values should not include this constant. Is there a way to keep this warning, but to avoid it for such special values? I.e.
switch(foo) { case FOO_ONE: anything; };
should give a warning, but:
switch(foo) { case FOO_ONE: anything; case FOO_TWO: anything_else; }
should not .
source share