https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98142
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Barry Revzin from comment #2) > I guess in general this is kind of a scary optimization, since it doesn't > seem like it's really a global thing? Perhaps this calls for an attribute? > > [[gnu::i_promise_on_penalty_of_ub_that_only_these_values_are_used]] > enum class E : unsigned int { A, B, C, D }; > > Or, you know, [[gnu::strict_enum]] or something. It couldn't be called "strict_enum". The -fstrict-enums flag means assume no invalid values, i.e. nothing outside the valid values of the enum type. For any enum type with a fixed underlying type, all values of the underlying type are valid values of the enum type, so there are no invalid values. So "strict_enum" as the attribute name would be contradicting the meaning of -fstrict-enums. So purely on that basis, the better name would be "i_promise_on_penalty_of_ub_that_only_these_values_are_used"