struct Foo {};
struct Bar {};
int Baz(const Foo&) { return 0; }
int Baz(Bar&&) { return 1; }
int main()
{
return Baz({});
}
Is this call ambiguous? MSVC chooses the rvalue reference overload. GCC says it is ambiguous. Clang also chooses the rvalue reference but no longer if it's int Baz(std::vector<Bar>&&) instead or if Bar gets a constructor taking a std::initializer_list.
Is {} to Bar a standard conversion sequence?
Can someone explain why this does or does not apply:
- A standard conversion sequence S1 is better than a standard conversion sequence S2 if
[...]
c) or, if not that, both S1 and S2 are binding to a reference parameter to something other than the implicit object parameter of a ref-qualified member function, and S1 binds an rvalue reference to an rvalue while S2 binds an lvalue reference to an rvalue
(https://en.cppreference.com/w/cpp/language/overload_resolution)