This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-07-24
[Accepted as a DR at the November, 2023 meeting.]
Consider:
enum class E {E1}; void f() { E e; e = E{0}; // #1 e = {0}; // #2 }
#1 first initializes a temporary of type E and then assigns that to e. For #2, 7.6.19 [expr.ass] bullet 8.1 specifies that #2 is equivalent to #1:
A braced-init-list may appear on the right-hand side of
- an assignment to a scalar, in which case the initializer list shall have at most a single element. The meaning of x = {v}, where T is the scalar type of the expression x, is that of x = T{v}. The meaning of x = {} is x = T{}.
- ...
However, there is no syntactic hint that #2 would invoke direct-initialization, and in fact gcc, icc, and MSVC reject #2, but clang accepts.
Proposed resolution (approved by CWG 2023-11-06):
Change in 7.6.19 [expr.ass] paragraph 8 as follows:
A braced-init-list B may appear on the right-hand side of
- an assignment to a scalar of type T, in which case
the initializer listB shall have at most a single element. The meaning of x ={v}B is x = t, where t is an invented temporary variable declared and initialized as T t = B, where T is the scalar type of the expression x, is that of x = T{v}. The meaning of x = {} is x = T{}.- an assignment to an object of class type, in which case
the initializer listB is passed as the argument to the assignment operator function selected by overload resolution (12.4.3.2 [over.ass], 12.2 [over.match]).