Lets consider simple reduced example
struct Foo {};
struct Bar : Foo {};
struct Baz : Foo {};
struct X {
operator Bar() { std::cout << "Bar\n"; return {}; }
operator Baz() const { std::cout << "Baz\n"; return {}; }
};
void foo(const Foo &f) {}
int main() {
foo(X{});
}
Here both GCC and clang are printing "Bar", see godbolt example
I am struggling to understand why.
There is no problem to call const-annotated method in rvalue object, see this example
So lets build ICS:
X{} -> user conversion -> Bar -> const Foo&
X{} -> user conversion -> Buz -> const Foo&
Both ICS have 1 user conversion and equivalent standard conversion tail. This shall be ambiguity by [over.ics.rank] C++20.
Can someone help to motivate what happens? I don't believe both mainline compilers agree and wrong here.