CWG Issue 1418 (original) (raw)
This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 117a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-04-13
1418. Type of initializer_list backing array
Section: 9.5.5 [dcl.init.list]Status: CD3Submitter: Johannes SchaubDate: 2011-11-19
[Moved to DR at the October, 2012 meeting.]
According to 9.5.5 [dcl.init.list] paragraph 5, the elements of the backing array for an object of typestd::initializer_list are of typeE. This is contradicted by the wording of 17.11 [support.initlist] paragraph 2.
Proposed resolution (February, 2012):
Change 9.5.5 [dcl.init.list] paragraph 5 as follows:
An object of type std::initializer_list is constructed from an initializer list as if the implementation allocated an array of N elements of type constE, where N is the number of elements in the initializer list. Each element of that array is copy-initialized with the corresponding element of the initializer list, and thestd::initializer_list object is constructed to refer to that array. If a narrowing conversion is required to initialize any of the elements, the program is ill-formed. [Example:
struct X { X(std::initializer_list v); }; X x{ 1,2,3 };
The initialization will be implemented in a way roughly equivalent to this:
const double __a[3] = {double{1}, double{2}, double{3}}; X x(std::initializer_list(__a, __a+3));
assuming that the implementation can construct an initializer_list object with a pair of pointers. —_end example_]