Title
Template initializer-list constructors
Status
c++14
Section
9.4.5 [dcl.init.list]
Submitter
Daveed Vandevoorde

Created on 2012-06-06.00:00:00 last changed 113 months ago

Messages

Date: 2013-09-15.00:00:00

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

Date: 2013-06-15.00:00:00

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]
Date: 2013-01-15.00:00:00

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}};
Date: 2012-10-15.00:00:00

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;...
Date: 2012-06-06.00:00:00

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?

History
Date User Action Args
2014-11-24 00:00:00adminsetstatus: drwp -> c++14
2014-03-03 00:00:00adminsetstatus: dr -> drwp
2013-10-14 00:00:00adminsetmessages: + msg4690
2013-10-14 00:00:00adminsetstatus: tentatively ready -> dr
2013-09-03 00:00:00adminsetmessages: + msg4459
2013-09-03 00:00:00adminsetstatus: drafting -> tentatively ready
2013-05-03 00:00:00adminsetstatus: review -> drafting
2013-01-14 00:00:00adminsetmessages: + msg4202
2013-01-14 00:00:00adminsetstatus: tentatively ready -> review
2012-11-03 00:00:00adminsetmessages: + msg4075
2012-11-03 00:00:00adminsetstatus: open -> tentatively ready
2012-06-06 00:00:00admincreate