enumeration value ... not handled in switch
Joerg Faschingbauer
jfasch@aon.at
Wed Sep 26 10:55:00 GMT 2001
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
More information about the Gcc
mailing list