Created on 2023-07-06.00:00:00 last changed 7 months ago
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]).
[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.
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-11-07 07:37:14 | admin | set | status: review -> ready |
2023-09-15 21:51:11 | admin | set | messages: + msg7429 |
2023-09-15 21:51:11 | admin | set | status: open -> review |
2023-07-06 00:00:00 | admin | create |