Title
Copy-list-initialization and explicit constructors
Status
nad
Section
12.2.2.8 [over.match.list]
Submitter
Daniel Krügler

Created on 2010-12-03.00:00:00 last changed 165 months ago

Messages

Date: 2011-03-15.00:00:00

Rationale (March, 2011):

The current rules are as intended.

Date: 2022-11-20.07:54:16

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});
    }
History
Date User Action Args
2011-04-10 00:00:00adminsetmessages: + msg3418
2011-04-10 00:00:00adminsetstatus: open -> nad
2010-12-03 00:00:00admincreate