This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: enumeration value ... not handled in switch


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]