Title
Enumeration list-initialization from the same type
Status
drwp
Section
9.4.5 [dcl.init.list]
Submitter
Richard Smith

Created on 2016-03-22.00:00:00 last changed 2 weeks ago

Messages

Date: 2023-10-06.22:55:13

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.
Date: 2023-09-15.21:23:20

CWG 2023-09-15

Class types with conversions to scalar types were not in view when the wording in this bullet was conceived.

Date: 2023-08-15.00:00:00

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.

Date: 2018-03-15.00:00:00

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.

Date: 2023-11-15.00:00:00

[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:46adminsetstatus: dr -> drwp
2023-12-19 10:15:28adminsetstatus: ready -> dr
2023-10-06 22:55:13adminsetstatus: review -> ready
2023-09-15 21:23:20adminsetmessages: + msg7426
2023-09-15 21:23:20adminsetmessages: + msg7425
2023-08-27 05:32:49adminsetmessages: + msg7410
2018-04-11 00:00:00adminsetmessages: + msg6186
2018-04-11 00:00:00adminsetstatus: open -> review
2016-03-22 00:00:00admincreate