enumeration value ... not handled in switch

hartmut.schirmer@arcormail.de hartmut.schirmer@arcormail.de
Tue Jan 11 14:28:00 GMT 2005


Hi,

[...] 
> As it seems, this problem cannot be solved without adding an attribute
> that declares a default case to be exceptional.
> 
> Consider the following code:
> 
>    struct fruit
>    {
>      enum { APPLE, MELON, ORANGE } type;
>      ...
>    } fruit;
[...]

Adding another fruit BANANA

> [...] should fail as
> quickly and noisily as possible:
> 
>    switch (fruit.type)
>      {
>        case APPLE:
>          ...; break;
>        case MELON:
>          ...; break;
>        case ORANGE:
>          ...; break;
>        default:
>          abort ();
>      }

This may produce a warning like
enum value 'BANANA' triggers noreturn function 'abort' in switch

Creating something like __builtin_warning()

    switch (fruit.type)
      {
        case APPLE:
          ...; break;
        case MELON:
          ...; break;
        case ORANGE:
          ...; break;
        default:
          __builtin_warning();
      }

could trigger a similar warning without changing the control flow.

Hartmut


Arcor-DSL: die echte Flatrate für alle Bandbreiten. Jetzt ohne Einrichtungspreis
einsteigen oder wechseln. Arcor-DSL ist in vielen Anschlussgebieten verfügbar.
http://www.arcor.de/home/redir.php/emf-dsl-1



More information about the Gcc mailing list