This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: enumeration value ... not handled in switch
- From: hartmut dot schirmer at arcormail dot de
- To: gcc at gcc dot gnu dot org
- Date: Tue, 11 Jan 2005 14:42:32 +0100 (CET)
- Subject: Re: enumeration value ... not handled in switch
- References: <33522584.1105449855947.JavaMail.ngmail@webmail-05.arcor-online.net> <87k6qkr0nt.fsf@wigwam.deepwood.net> <1F5C7ECB324CD411B58600D0B723F181779402@oehhex01.becker.de>
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