enumeration value ... not handled in switch

Schirmer, Hartmut SchirmerH@Innovative-Systems.de
Wed Sep 26 09:03:00 GMT 2001


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.

Hartmut



More information about the Gcc mailing list