Given: int main(void) { enum foo { A, B, C, D} bar; bar = D; if(bar == A) { ; } else if(bar == B) { ; } else { switch(bar) { case C: case D: ; } } return 0; }
barbeque/zarathustra:src: /usr/local/bin/gcc-4.1.0 -Wswitch-enum a.c a.c: In function 'main': a.c:10: warning: enumeration value 'A' not handled in switch a.c:10: warning: enumeration value 'B' not handled in switch A & B aren't valid targets for the switch statement by the time it's hit as they have been handled by the if statements above. Locally built gcc: barbeque/zarathustra:src: /usr/local/bin/gcc-4.1.0 -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.1.0/configure --prefix=/usr/local/stow/gcc-4.1.0 --enable-languages=c,c++,objc --infodir=/usr/local/stow/gcc-4.1.0/share/info --mandir=/usr/local/stow/gcc-4.1.0/share/man --enable-shared --enable-threads --enable-tls --program-suffix=-4.1.0 --enable-__cxa_atexit --enable-version-specific-runtime-libs --enable-targets=x86_64-unknown-linux-gnu --enable-bootstrap=lean --disable-biarch --disable-multilib Thread model: posix gcc version 4.1.0 On Debian/stable from amd64.debian.net. Also happens on gcc 3.3.5 from the Debian apt archives. -- Summary: -Wswitch-enums doesn't detect impossible cases in switch() Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ramune+gcc at net-ronin dot org GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27126