From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12822 invoked by alias); 11 Jan 2005 16:04:58 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 12223 invoked from network); 11 Jan 2005 16:03:32 -0000 Received: from unknown (HELO mxfep02.bredband.com) (195.54.107.73) by sourceware.org with SMTP; 11 Jan 2005 16:03:32 -0000 Received: from wigwam ([213.112.182.104] [213.112.182.104]) by mxfep02.bredband.com with ESMTP id <20050111160331.PBKS24538.mxfep02.bredband.com@wigwam>; Tue, 11 Jan 2005 17:03:31 +0100 Received: from localhost ([127.0.0.1] helo=wigwam) by wigwam with esmtp (Exim 4.34) id 1CoOUu-0003D7-3f; Tue, 11 Jan 2005 17:03:56 +0100 To: hartmut.schirmer@arcormail.de Cc: gcc@gcc.gnu.org Subject: Re: Aw: Re: enumeration value ... not handled in switch References: <87k6qkr0nt.fsf@wigwam.deepwood.net> <1F5C7ECB324CD411B58600D0B723F181779402@oehhex01.becker.de> <17455984.1105449856020.JavaMail.ngmail@webmail-05.arcor-online.net> From: Daniel Brockman Date: Tue, 11 Jan 2005 17:00:00 -0000 In-Reply-To: <17455984.1105449856020.JavaMail.ngmail@webmail-05.arcor-online.net> (hartmut schirmer's message of "Tue, 11 Jan 2005 14:24:16 +0100 (CET)") Message-ID: <876524q7f8.fsf@wigwam.deepwood.net> User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2005-01/txt/msg00632.txt.bz2 hartmut.schirmer@arcormail.de writes: > 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 I don't see how triggering noreturn functions in a switch in itself warrants a warning. I have lots of code that looks like this: void eat_small_fruit (struct fruit *fruit) { switch (fruit.type) { case APPLE: ...; break; case MELON: abort (); case ORANGE: ...; break; } } Here, passing a melon to `eat_small_fruit' is a programmer error, because a melon is not considered to be a small fruit. > 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. That suffers the same problem. Should this trigger a warning? void eat_small_fruit (struct fruit *fruit) { switch (fruit.type) { case APPLE: ...; break; case MELON: __builtin_warning (); case ORANGE: ...; break; } } Regards, -- Daniel Brockman