by garethrees · 7y ago · 0 comments
XOR may be rarely used, but 2^8 is not only one of the most common accidental XORs, it's also probably one of the more common legitimate uses of it.
Nope, the warning would be for literal numbers in the source. IMO anyone who doesn't define constants for the flag bits deserves the warning.
The preprocessor does macro expansion, the compiler compiles the result.
The compiler does not see FLAG_BIT1 ^ FLAG_BIT3, it only sees the result, e.g. 2^32.
Therefore to catch only explicit 2^32 the warning should come from the preprocessor... Nice mess created right there.
Interestingly, msvc can also do this, by virtue of not even having a distinct preprocessor phase at all.