In some header file which I can not modify I have the following set of defines:
#define FLAG1 (0x0000_0001)
#define FLAG2 (0x0000_0002)
...
Then, in my code I use them in switch:
switch (aaa) {
case FLAG1:
....
case FLAG2:
....
}
As a result, Coverity reports on 2 defects per each case label:
RW.EXP_RPAREN:
Event exp_rparen: expected a ")"
RW.CASE_LABEL_CONFLICT:
Event case_label_conflict: case label value has already appeared in
this switch at line XX
What is wrong with these case labels? Does it violate C standards?
case 4*(1+2):
should be valid as well. – Autogamyenum
. You might write (with slashes for newlines):#undef FLAG1 / #undef FLAG2 / enum { FLAG1 = 0x0001, FLAG2 = 0x0002 };
. That undoes the damage from the erroneous header and gives you better debugging (becauseenum
symbols are conveyed to the debugger, but preprocessor symbols usually are not). – Arrowworm