https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98142
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Barry Revzin from comment #0) > As desired. I am telling gcc to make an assumption about the range of > values, and it is optimizing based on the fact that 5 is not a valid > enumerator. N.B. it has nothing to do with whether it's an enumerator. Given enum E2 { zero, two=2 } this has the same range of valid values, and so E2(1) and E2(3) are valid, even though there are no enumerators with those values, and E2(3) has a higher value than two. The only enumerators that matter are the ones with the minimum and maximum values, as those determine the range of valid values as per [dcl.enum] p8. All other enumerators are just named constants, they have no bearing on the valid values or optimizations. All values within the enum's range are valid, whether there is an enumerator with that value or not. What you're asking for is not how C++ enumeration types work, although it is how many, many people think they work, or want them to work.