https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88895
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic Status|UNCONFIRMED |NEW Last reconfirmed| |2019-01-17 CC| |msebor at gcc dot gnu.org Component|c++ |c Ever confirmed|0 |1 --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed. The warning is not specific to C++ but triggers for C code as well (see the example below). The reason for the false positive is that the warning is implemented in the front-ends and doesn't benefit from any control flow analysis, and so it triggers before the switch statement has been optimized and the unreachable labels eliminated. To avoid it the warning would have to be deferred until quite a bit later. $ cat u.c && gcc -S -Wall -Wextra -Wpedantic u.c static inline int f (int i) { switch (sizeof i) { case 8: return i >> 56; case 4: return i >> 24; case 2: return i >> 8; case 1: return i; } } int g (int i) { return f (i); } u.c: In function âfâ: u.c:5:22: warning: right shift count >= width of type [-Wshift-count-overflow] 5 | case 8: return i >> 56; | ^~