This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [c++] switch ( enum ) vs. default statment.
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>
- Cc: PaweÅ Sikora <pluto at agmk dot net>, "Mark Mitchell" <mark at codesourcery dot com>, gcc at gcc dot gnu dot org, ralf at linux-mips dot org
- Date: Tue, 06 Feb 2007 16:44:50 -0200
- Subject: Re: [c++] switch ( enum ) vs. default statment.
- References: <45BDC001.8000801@agmk.net> <6c33472e0701290306j66b7decfxfdc7910570ff3018@mail.gmail.com>
On Jan 29, 2007, "Manuel LÃpez-IbÃÃez" <lopezibanez@gmail.com> wrote:
> * You can add a return 0 or an exit(1) at the end of the function or
> in a default label. Since in your case the code is unreachable, the
> optimiser may remove it or it will never be executed.
But this would generate additional code for no useful purpose.
See Ralf Baechle's posting with Subject: False ânoreturnâ function
does return warnings.
/me thinks it would make sense for us to add a __builtin_unreachable()
that would indicate to GCC that no further action is needed from that
point on. A command-line flag could then tell whether GCC should
generate abort() for such cases, or take a more general "undefined
behavior" approach without generating additional code to that end.
Meanwhile, there's __builtin_trap() already, and Ralf might use that
even to remove the asm volatile, and PaweÅ could use it in a default:
label. It's still worse than a __builtin_assume(e == X || e == Y),
but it's probably much simpler to implement. But then,
__builtin_unreachable() might very well be implemented as
__builtin_assume(0).
--
Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member http://www.fsfla.org/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}