Title
Undefined behavior converting to short enums with fixed underlying types
Status
cd5
Section
7.6.1.9 [expr.static.cast]
Submitter
Thomas Köppe

Created on 2017-03-24.00:00:00 last changed 2 months ago

Messages

Date: 2017-08-15.00:00:00

Proposed resolution (August, 2017):

Change 7.6.1.9 [expr.static.cast] paragraph 10 as follows:

A value of integral or enumeration type can be explicitly converted to a complete enumeration type. The If the enumeration type has a fixed underlying type, the value is first converted to that type by integral conversion, if necessary, and then to the enumeration type. If the enumeration type does not have a fixed underlying type, the value is unchanged if the original value is within the range of the enumeration values (9.7.1 [dcl.enum]). Otherwise, and otherwise, the behavior is undefined.
Date: 2017-11-15.00:00:00

[Accepted as a DR at the November, 2017 meeting.]

The specifications of std::byte (17.2.5 [support.types.byteops]) and bitmask (16.3.3.3.4 [bitmask.types]) have revealed a problem with the integral conversion rules, according to which both those specifications have, in the general case. undefined behavior. The problem is that a conversion to an enumeration type has undefined behavior unless the value to be converted is in the range of the enumeration.

For enumerations with an unsigned fixed underlying type, this requirement is overly restrictive, since converting a large value to an unsigned integer type is well-defined.

History
Date User Action Args
2020-12-15 00:00:00adminsetstatus: dr -> cd5
2018-02-27 00:00:00adminsetmessages: + msg6111
2017-03-24 00:00:00admincreate