This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114b. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-05-06


2638. Improve the example for initializing by initializer list

Section: 9.4.5  [dcl.init.list]     Status: DR     Submitter: Shafik Yaghmour     Date: 2022-10-26

[Accepted as a DR at the March, 2024 meeting.]

Issue 2137 amended the rules for initialization by initializer list, but neglected to add an example.

Proposed resolution (approved by CWG 2023-11-11):

Change the example in 9.4.5 [dcl.init.list] bullet 3.7 as follows:

struct S {
  S(std::initializer_list<double>); // #1
  S(std::initializer_list<int>);    // #2
  S(std::initializer_list<S>);      // #3
  S();                              // #3#4

  // ...
};
S s1 = { 1.0, 2.0, 3.0 };  // invoke #1
S s2 = { 1, 2, 3 };        // invoke #2
S s3{s2};                  // invoke #3 (not the copy constructor)
S s3s4 = { };              // invoke #3#4