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

2023-02-07


1508. Template initializer-list constructors

Section: 9.4.5  [dcl.init.list]     Status: C++14     Submitter: Daveed Vandevoorde     Date: 2012-06-06

[Moved to DR at the September, 2013 meeting.]

Can a constructor template ever be an initializer-list constructor without std::initializer_list (or an alias template specialization for it) appearing in the template signature? E.g., is there any way that the constructor in:

  struct S {
    template<typename T> S(T);
  };

can be an initializer-list constructor?

Proposed resolution (October, 2012) [superseded]:

Modify 9.4.5 [dcl.init.list] paragraph 2 as follows:

A constructor is an initializer-list constructor if its first parameter is of type std::initializer_list<E> or reference to possibly cv-qualified std::initializer_list<E> for some type E, and either there are no other parameters or else all other parameters have default arguments (9.3.4.7 [dcl.fct.default]). [Note: Initializer-list constructors are favored over other constructors in list-initialization (12.2.2.8 [over.match.list]). Given a class C, a constructor template such as template<class T> C(T) is never instantiated to produce an initializer-list constructor, because an initializer list argument causes the corresponding parameter to be a non-deduced context (13.10.3.2 [temp.deduct.call]).end note] The template std::initializer_list is not predefined;...

Additional note (January, 2013):

The wording of the new note needs to be adjusted, because such a constructor template might have a default template argument that is a specialization of std::initializer_list. For example:

  struct D {
    template<typename T = std::initializer_list<int>> D(T);
  };
  D d{{1, 2, 3}};

Proposed resolution (June, 2013):

Change the note in 9.4.5 [dcl.init.list] paragraph 2 as follows:

[Note: Initializer-list constructors are favored over other constructors in list-initialization (12.2.2.8 [over.match.list]). Passing an initializer list as the argument to the constructor template template<class T> C(T) of a class C does not create an initializer-list constructor, because an initializer list argument causes the corresponding parameter to be a non-deduced context (13.10.3.2 [temp.deduct.call]).end note]