Title
Overly permissive specification of enum direct-list-initialization
Status
c++20
Section
9.4.5 [dcl.init.list]
Submitter
Shafik Yaghmour

Created on 2018-02-18.00:00:00 last changed 7 months ago

Messages

Date: 2019-10-15.00:00:00

Proposed resolution (October, 2019):

Change bullet 3.8 of 9.4.5 [dcl.init.list] 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, 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 the underlying type of T U, the program is ill-formed. [Example:...

Date: 2019-05-15.00:00:00

Proposed resolution (May, 2019): [SUPERSEDED]

Change bullet 3.8 of 9.4.5 [dcl.init.list] as follows:

  • Otherwise, if T is an enumeration with a fixed underlying type (9.7.1 [dcl.enum]), the initializer-list has a single element v, v can be implicitly converted to the underlying type of T, 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. [Example:...

Date: 2018-10-15.00:00:00

Notes from the October, 2018 teleconference:

CWG agreed with the suggested direction, along the lines of “...can be implicitly converted to the underlying type of T...”

Date: 2019-11-15.00:00:00

[Adopted as a DR at the November, 2019 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.

The conversion T(v) is too broad, allowing, e.g., conversion from a different scoped enumeration type. The intent presumably was only to allow v to be a value of T's underlying type.

History
Date User Action Args
2020-12-15 00:00:00adminsetmessages: + msg6461
2020-12-15 00:00:00adminsetmessages: + msg6460
2020-12-15 00:00:00adminsetmessages: + msg6459
2018-02-18 00:00:00admincreate