Optimize based on possible enum class values?
Jonathan Wakely
jwakely.gcc@gmail.com
Mon May 23 19:36:00 GMT 2016
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.
More information about the Gcc-help
mailing list