https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95701
Bug ID: 95701 Summary: undefined enum conversion accepted in constant expression Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: leni536 at gmail dot com Target Milestone: --- gcc accepts the following code: enum E { one = 1 }; constexpr E foo() { return static_cast<E>(0xffff); } void bar() { constexpr auto e = foo(); } Relevant parts of the standard: https://timsong-cpp.github.io/cppwp/n4659/expr.const#2.6 https://timsong-cpp.github.io/cppwp/n4659/expr.static.cast#10 > The value is unchanged if the original value is within the range of the > enumeration values ([dcl.enum]). Otherwise, the behavior is undefined. https://timsong-cpp.github.io/cppwp/n4659/dcl.enum#8 Following the wording here the "range of the enumeration values" is [0, 1].