Community
Participate
Working Groups
I just wrote this subtly silly code long crc = crc32.getValue(); if (crc == 0x42132087 || crc == 0xdb1b9859) doSomething(); and now I'm wondering if the compiler could have warned me: the first comparison works as expected but for the second constant the value wraps around the int range resulting in a negative int which is then compared to a long where no wrapping would have occurred. The scenario to warn about would be: - comparing long to in - int is a hex or oct constant (issue cannot be produced with dec constant) - the constant represents a negative value (no unary minus involved) The proposed fix would be: - append "L" to the constant
In that case, it might be relevant to have such a warning not just in comparisons but also in assignments, case statements, etc. no?
Sounds like a good exercise for a new contributor :)