second standard conversion sequence for constructor

65 views
Skip to first unread message

Waylander

unread,
Jan 7, 2016, 9:17:08 AM1/7/16
to ISO C++ Standard - Discussion
The Standard (n4296) 13.3.3.2 [over.ics.rank] (3.3) says:
 
— User-defined conversion sequence U1 is a better conversion sequence than another user-defined conversion
sequence U2 if they contain the same user-defined conversion function or constructor or they
initialize the same class in an aggregate initialization and in either case the second standard conversion
sequence of U1 is better than the second standard conversion sequence of U2. [ Example:
 
struct A {
operator short();
} a;
int f(int);
int f(float);
int i = f(a); // calls f(int), because short ! int is better than short ! float.
 
—end example ]

Could someone give an example where the second standard conversion sequence take place, except in the case with a conversion function? I think that a converting constructor always (?) gives the second sequence as identity, because it constructs a destination type immediately, without following conversions.

Columbo

unread,
Jan 7, 2016, 8:58:14 PM1/7/16
to ISO C++ Standard - Discussion, Jac...@mail.ru
Good point, for there is (AFAICS) no spot in the standard that makes it possible for a UCS's second SCS not to be the identity conversion if it invokes a constructor. In fact, the only place that explicitly specifies that second SCS is [over.ics.list] (p6, p7). Maybe the sentence you quoted was composed by simply enumerating all kinds of functions invoked by user-defined conversions? Perhaps the author of the section wanted to avoid any (more or less) profound exclusions?

Btw., it appears the wording in your quote is weird anyway, because a constructor is a "user-defined conversion function" (at least as implied by [over.ics.user]/4). Although, then again, that term isn't normatively defined (and "user-defined" could be taken as a separate adjective)...
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Waylander

unread,
Jan 8, 2016, 10:07:32 AM1/8/16
to ISO C++ Standard - Discussion
I found another place where SCS is referred to ([over.ics.ref]):
If the parameter binds directly to the result of applying a conversion function to the
argument expression, the implicit conversion sequence is a user-defined conversion sequence (13.3.3.1.2),
with the second standard conversion sequence either an identity conversion or, if the conversion function
returns an entity of a type that is a derived class of the parameter type, a derived-to-base Conversion
.
But again, that case is only for a conversion operator, because constructors of derived classes is not considered for the following derived-to-base conversion
Reply all
Reply to author
Forward
0 new messages