This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 117b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-08-11
2768. Assignment to enumeration variable with a braced-init-listSection: 7.6.19 [expr.assign] Status: DRWP Submitter: Shafik Yaghmour Date: 2023-07-06[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.assign] 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.assign] 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 list B 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 list B is passed as the argument to the assignment operator function selected by overload resolution (12.4.3.2 [over.assign], 12.2 [over.match]).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4