[Bug c++/93674] GCC eliminates conditions it should not, when strict-enums is on

gbuella at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Feb 11 12:10:00 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93674

--- Comment #2 from Gábor Buella <gbuella at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> -fstrict-enums
> Allow the compiler to optimize using the assumption that a value of
> enumerated type can only be one of the values of the enumeration (as defined
> in the C++ standard; basically, a value that can be represented in the
> minimum number of bits needed to represent all the enumerators). This
> assumption may not be valid if the program uses a cast to convert an
> arbitrary integer value to the enumerated type.
> 
> ---- CUT ---
> I assume that means since there is no negative numbers in the enum, that
> means you might get undefined behavior if j is negative ...

Look at the code, j is never negative when the cast is applied.
You can easily verify it by printing the e.g. values.


More information about the Gcc-bugs mailing list