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

2024-10-26


1418. Type of initializer_list backing array

Section: 9.4.5  [dcl.init.list]     Status: CD3     Submitter: Johannes Schaub     Date: 2011-11-19

[Moved to DR at the October, 2012 meeting.]

According to 9.4.5 [dcl.init.list] paragraph 5, the elements of the backing array for an object of type std::initializer_list<E> are of type E. This is contradicted by the wording of 17.10 [support.initlist] paragraph 2.

Proposed resolution (February, 2012):

Change 9.4.5 [dcl.init.list] paragraph 5 as follows:

An object of type std::initializer_list<E> is constructed from an initializer list as if the implementation allocated an array of N elements of type const E, 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 the std::initializer_list<E> 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<double> 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<double>(__a, __a+3));

assuming that the implementation can construct an initializer_list object with a pair of pointers. —end example]