This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: enumeration value ... not handled in switch
- To: SchirmerH at Innovative-Systems dot de
- Subject: RE: enumeration value ... not handled in switch
- From: Joerg Faschingbauer <jfasch at aon dot at>
- Date: Wed, 26 Sep 2001 19:53:58 +0500
- Cc: jfasch at aon dot at, gcc at gcc dot gnu dot org
- References: <1F5C7ECB324CD411B58600D0B723F181779422@oehhex01.becker.de>
From: "Schirmer, Hartmut" <SchirmerH@Innovative-Systems.de>
Subject: RE: enumeration value ... not handled in switch
Date: Wed, 26 Sep 2001 18:05:02 +0200
> Hi,
>
> > This is bug #3780. I'll be cleaning up my patch a bit (although it
> > won't become less dirty by doing so :-) and submit it. (This won't
> > happen before two weeks, though.)
>
> not really the same problem.
>
> In my C code (not C++) I have
>
> enum { A, B, C } x;
>
> switch (x)
> {
> case A:
> case B:
> case C:
> break;
> default:
> // strange
> abort();
> }
>
> The default case is for runtime safty. The variable x may be in an
> illegal state (not initialized, corupted, ...)
>
> If I later add a D to the enum I won't get a warning because of
> the default case. Changing the code to
>
> switch (x)
> {
> case A:
> case B:
> case C:
> break;
> default attribute(silent):
> // strange
> abort();
> }
>
> enables the compile time analysis so I don't have to wait for
> a runtime error.
I obviously misunderstood.
Joerg