Copy-list-initialization and explicit constructors in overload resolution

45 views
Skip to first unread message

dyp

unread,
Jan 11, 2016, 4:23:03 PM1/11/16
to std-dis...@isocpp.org
CWG 1228 contains the following example:

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});
}

Unfortunately, CWG's response to the issue does not say how this example
shall be interpreted. From what I understand, [over.match.list] does
consider explicit constructors viable for overload resolution, but makes
the program ill-formed if the final overload result contains an explicit
constructor called by copy-list-init. In the context of the above
example, this should lead to an ambiguity.

Is this interpretation correct?

Furthermore, why was [over.match.list] changed between N2640 and N2672?


Thanks and kind regards,

dyp

Johannes Schaub

unread,
Jan 11, 2016, 6:11:35 PM1/11/16
to std-dis...@isocpp.org
2016-01-11 22:24 GMT+01:00 dyp <dyp...@gmx.net>:
> CWG 1228 contains the following example:
>
> 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});
> }
>
> Unfortunately, CWG's response to the issue does not say how this example
> shall be interpreted. From what I understand, [over.match.list] does
> consider explicit constructors viable for overload resolution, but makes
> the program ill-formed if the final overload result contains an explicit
> constructor called by copy-list-init. In the context of the above
> example, this should lead to an ambiguity.
>
> Is this interpretation correct?
>

Yes this is correct. See
http://compgroups.net/comp.lang.c++.moderated/why-aren-t-explicit-constructors-igno/414263
and the follow-up with apparently a link to the rationale.

Johannes Schaub

unread,
Jan 11, 2016, 6:14:01 PM1/11/16
to std-dis...@isocpp.org
( apparently that PDF moved to http://www.stroustrup.com/list-issues-2.pdf )
Reply all
Reply to author
Forward
0 new messages