C++ Logo

std-discussion

Advanced search

[over.ics.rank] standard conversion tie-breakers from different source types

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Mon, 9 Jan 2023 23:04:09 +0000
Hi,

I would like an example of a function call to an overloaded function,
where the most viable function is determined by the rules listed from
[over.ics.rank]/4.4.5 to [over.ics.rank]/4.4.8:

https://timsong-cpp.github.io/cppwp/n4868/over.ics.rank#4.4.5

These are four different tie-breakers for ranking standard conversions
from different source types, assuming the following class hierarchy:

struct A {}; struct B : C {}; struct C : B {};

(4.4.5) conversion of B* to A* is better than conversion of C* to A*,
(4.4.6) binding of an expression of type B to a reference to type A is
better than binding an expression of type C to a reference to type A,
(4.4.7) conversion of B​::​* to C​::​* is better than conversion of
A​::​* to C​::​*, and
(4.4.8) conversion of B to A is better than conversion of C to A.

The note says that these are only used for tie-breakers in the second
conversion sequence of user-defined conversions:

https://timsong-cpp.github.io/cppwp/n4868/over.ics.rank#note-1

However if two user-defined conversions yield different types before
the second conversion sequence, then they are necessarily have to use
different user-defined conversion functions or constructors, so the
conversion sequences would be indistinguishable by [over.ics.rank]/3,
as [over.ics.rank]/3.3 does not apply:

https://timsong-cpp.github.io/cppwp/n4868/over.ics.rank#3.3

Having said that I have no idea what "or they initialize the same
class in an aggregate initialization" means here, maybe that's the key.

Cheers,
Lénárd

Received on 2023-01-09 23:04:17