This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimize based on possible enum class values?
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: lh mouse <lh_mouse at 126 dot com>
- Cc: âJosh Chia <joshchia at gmail dot com>, gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Mon, 23 May 2016 20:36:44 +0100
- Subject: Re: Optimize based on possible enum class values?
- Authentication-results: sourceware.org; auth=none
- References: <CALxtSbTS96dhLiLa7ujcbpdjPSsU20SWFNjk4h6PYccq-bXHWg at mail dot gmail dot com> <74a21614 dot 149394 dot 154c6b671ff dot Coremail dot lh_mouse at 126 dot com>
On 19 May 2016 at 02:52, lh mouse wrote:
> -fstrict-enums
>
> This option is for C++ only.
In this example the enumeration type has a fixed underlying type, so
the valid values of the enumeration are all the valid values of the
underlying type, which allows 0-255. It can't assume that there isn't
code that does:
E e = E{255};
So -fstrict-enums isn't enough to tell the compiler that only the
values 0, 1 and 2 will be used.
As others have replied, __builtin_unreachable() can be used for that.