https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104205
Bug ID: 104205 Summary: Signed overflow in case label reports confusing warning with -Wpedantic Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: stephen.wassell at sophos dot com Target Milestone: --- When compiling the following code with "gcc -Wpedantic": int convert(int err) { switch (err) { case 1 << 31: // signed overflow - undefined behaviour return 0; default: return 1; } } int main() { return convert(1 << 31); } It reports a confusingly worded warning since version 6. It should say something about undefined behaviour instead. Should there also be a warning for the other use of 1 << 31? <source>: In function 'convert': <source>:5:9: warning: case label is not an integer constant expression [-Wpedantic] 5 | case 1 << 31: | ^~~~ Seen on gcc (Ubuntu 11.2.0-7ubuntu2) 11.2.0 x64, and multiple versions on Compiler Explorer. https://godbolt.org/z/4Tr1qxaqv