Created on 2016-03-22.00:00:00 last changed 7 months ago
Proposed resolution (approved by CWG 2023-10-06):
Change in 9.4.5 [dcl.init.list] bullet 3.8 as follows:
Otherwise, if T is an enumeration with a fixed underlying type (9.7.1 [dcl.enum]) U, the initializer-list has a single element v of scalar type, v can be implicitly converted to U, and the initialization is direct-list-initialization, the object is initialized with the value T(v) (7.6.1.4 [expr.type.conv]); if a narrowing conversion is required to convert v to U, the program is ill-formed.
CWG 2023-09-15
Class types with conversions to scalar types were not in view when the wording in this bullet was conceived.
Additional notes (August, 2023)
Issue 2374 has meanwhile clarified that v is required to implicitly convert to the underlying type of the enumeration for 9.4.5 [dcl.init.list] bullet 3.8 to apply. Now, the logic falls through to 9.4.5 [dcl.init.list] bullet 3.9 for the above example, making it well-formed.
Notes from the March, 2018 meeting:
CWG disagreed that the existing wording requires such a conversion, only that if such a conversion is possble, it must not narrow. A formulation along the lines of “if that initialization involves a narrowing conversion to the underlying type of T...” was suggested to clarify the intent. This will be handled editorially, and the issue will be left in "review" status until the change has been verified.
[Accepted as a DR at the November, 2023 meeting.]
According to 9.4.5 [dcl.init.list] bullet 3.8,
Otherwise, if T is an enumeration with a fixed underlying type (9.7.1 [dcl.enum]), the initializer-list has a single element v, and the initialization is direct-list-initialization, the object is initialized with the value T(v) (7.6.1.4 [expr.type.conv]); if a narrowing conversion is required to convert v to the underlying type of T , the program is ill-formed.
This could be read as requiring that there be a conversion from v to the underlying type of T, leaving the status of an example like the following unclear:
enum class E {};
struct X { operator E(); };
E{X()}; // ok?
History | |||
---|---|---|---|
Date | User | Action | Args |
2024-04-05 21:43:46 | admin | set | status: dr -> drwp |
2023-12-19 10:15:28 | admin | set | status: ready -> dr |
2023-10-06 22:55:13 | admin | set | status: review -> ready |
2023-09-15 21:23:20 | admin | set | messages: + msg7426 |
2023-09-15 21:23:20 | admin | set | messages: + msg7425 |
2023-08-27 05:32:49 | admin | set | messages: + msg7410 |
2018-04-11 00:00:00 | admin | set | messages: + msg6186 |
2018-04-11 00:00:00 | admin | set | status: open -> review |
2016-03-22 00:00:00 | admin | create |