[Bug c++/107622] Missing optimization of switch-statement

glisse at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Nov 11 15:07:39 GMT 2022


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

--- Comment #7 from Marc Glisse <glisse at gcc dot gnu.org> ---
(Wilhelm, when you post testcases, please post the full file including the
#include lines)

(In reply to Richard Biener from comment #5)
> Did you try -fstrict-enums?

IIUC, even if optimizations using -fstrict-enums were implemented, they would
only help with the first testcase if the number of enum values was a power of
2. For {A,B,C}, -fstrict-enums still considers 3 a valid value.

I have long wanted an attribute to specify that a particular enum is only
allowed to take the values explicitly listed, though I cannot find a relevant
issue in bugzilla at the moment.


Comment #4 is an independent issue where gcc fails to notice that since the
static variable does not escape, it can be replaced with a local constant.


More information about the Gcc-bugs mailing list