cplusplus / CWG

Core Working Group
23 stars 7 forks source link

[conv.integral] The conversion from unscoped enumeration to an integer type is underspecified #388

Open xmh0511 opened 1 year ago

xmh0511 commented 1 year ago

Full name of submitter (unless configured in github; will be published with the issue): Jim X

[conv.integral] p1

A prvalue of an integer type can be converted to a prvalue of another integer type. A prvalue of an unscoped enumeration type can be converted to a prvalue of an integer type.

[conv.integral] p4

The conversions allowed as integral promotions are excluded from the set of integral conversions.

Consider this example:

enum A:int{
   a
};
short c = A::a;

From an unscoped enumeration type to short is not covered in [conv.prom]. [enum.dcl.enum] 11 says:

The value of an enumerator or an object of an unscoped enumeration type is converted to an integer by integral promotion.

However, there does not exist a standard conversion sequence that would comprise both integer conversion and integer promotion since [conv.general] p1 says:

A standard conversion sequence is a sequence of standard conversions in the following order:

-[...]

  • Zero or one conversion from the following set: integral promotions, floating-point promotion, integral conversions, floating-point conversions, floating-integral conversions, pointer conversions, pointer-to-member conversions, and boolean conversions.

Suggested Resolution:

[conv.integral] should define how the conversion work to convert a prvalue of an unscoped enumeration type to integer type that is not covered in [conv.prom]. The wording may be:

The result of converting a prvalue of an unscoped enumeration type to a prvalue of an integer type is the same as converting the value of its underlying type to the integer type.