Bug 27126 - -Wswitch-enums doesn't detect impossible cases in switch()
Summary: -Wswitch-enums doesn't detect impossible cases in switch()
Status: RESOLVED DUPLICATE of bug 23577
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.1.0
: P5 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2006-04-12 08:05 UTC by Daniel N
Modified: 2006-04-13 01:27 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-04-12 10:17:19


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel N 2006-04-12 08:05:05 UTC
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.
Comment 1 Richard Biener 2006-04-12 10:17:19 UTC
Confirmed.  But this is unlikely to be fixed as it would require moving the diagnostic to the middle-end where this information is available.  And diagosticts from the middle-end are notoriously frowned upon.
Comment 2 Andrew Pinski 2006-04-13 01:27:22 UTC

*** This bug has been marked as a duplicate of 23577 ***