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

2024-12-19


1228. Copy-list-initialization and explicit constructors

Section: 12.2.2.8  [over.match.list]     Status: NAD     Submitter: Daniel Krügler     Date: 2010-12-03

The rules for selecting candidate functions in copy-list-initialization (12.2.2.8 [over.match.list]) differ from those of regular copy-initialization (12.2.2.5 [over.match.copy]): the latter specify that only the converting (non-explicit) constructors are considered, while the former include all constructors but state that the program is ill-formed if an explicit constructor is selected by overload resolution. This is counterintuitive and can lead to surprising results. For example, the call to the function object p in the following example is ambiguous because the explicit constructor is a candidate for the initialization of the operator's parameter:

    struct MyList {
      explicit MyStore(int initialCapacity);
    };

    struct MyInt {
      MyInt(int i);
    };

    struct Printer {
      void operator()(MyStore const& s);
      void operator()(MyInt const& i);
    };

    void f() {
      Printer p;
      p({23});
    }

Rationale (March, 2011):

The current rules are as intended.