Full name of submitter (unless configured in github; will be published with the issue): Benjamin Sch.
Reference (section label): [dcl.enum]
Issue description:
enum E { };
constexpr auto x = static_cast<E>(-1);
[dcl.enum]/8 specifies the range of E to be that of an (hypothetical) integer type with minimal width able to represent all enumerator values. For an empty enumeration [dcl.enum]/8 also specifies that the rule is applied as if a single enumerator with value 0 was present.
The minimal width here is 1, but both a signed and unsigned integer type with width 1 are able to represent the value 0. If it is the unsigned one, then static_cast<E>(-1) is UB and the declaration of x ill-formed. If it is the signed one, then -1 can be represented and static_cast<E>(-1) is not UB and the declaration of x well-formed.
Which of the two determines the value range of E?
If it is intentionally unspecified, then the static_cast with unspecified UB should be explicitly disallowed as core constant expression.
Full name of submitter (unless configured in github; will be published with the issue): Benjamin Sch.
Reference (section label): [dcl.enum]
Issue description:
[dcl.enum]/8 specifies the range of
Eto be that of an (hypothetical) integer type with minimal width able to represent all enumerator values. For an empty enumeration [dcl.enum]/8 also specifies that the rule is applied as if a single enumerator with value0was present.The minimal width here is
1, but both a signed and unsigned integer type with width1are able to represent the value0. If it is the unsigned one, thenstatic_cast<E>(-1)is UB and the declaration ofxill-formed. If it is the signed one, then-1can be represented andstatic_cast<E>(-1)is not UB and the declaration ofxwell-formed.Which of the two determines the value range of
E?If it is intentionally unspecified, then the
static_castwith unspecified UB should be explicitly disallowed as core constant expression.