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

2024-11-11


2194. Impossible case in list initialization

Section: 12.2.2.8  [over.match.list]     Status: drafting     Submitter: Robert Haberlach     Date: 2015-11-04

According to 12.2.2.8 [over.match.list] paragraph 1 says,

If the initializer list has no elements and T has a default constructor, the first phase is omitted.

However, this case cannot occur. If T is a non-aggregate class type with a default constructor and the initializer is an empty initializer list, the object will be value-constructed, per 9.4.5 [dcl.init.list] bullet 3.4. Overload resolution is only necessary if default-initialization (or a check of its semantic constraints) is implied, with the relevant section concerning candidates for overload resolution being 12.2.2.4 [over.match.ctor].

See also issue 1518.

Proposed resolution (January, 2017):

Change 12.2.2.8 [over.match.list] paragraph 1 as follows:

When objects of non-aggregate class type T are list-initialized such that 9.4.5 [dcl.init.list] specifies that overload resolution is performed according to the rules in this section, overload resolution selects the constructor in two phases:

If the initializer list has no elements and T has a default constructor, the first phase is omitted. In copy-list-initialization, if an explicit constructor is chosen...

Additional notes, February, 2017:

The statement of the issue is incorrect. In an example like

  struct A { A(); A(initializer_list<int>); };
  void f(A a);
  int main() { f({}); }

the rule in question is not used for the initialization of the parameter. However, it is used to determine whether a valid implicit conversion sequence exists for a. It is unclear whether an additional change to resolve this discrepancy is needed or not.