#include <iostream>
#include <string>
void fnc (const std::string&)
{
std::cout<<1;
}
void fnc (std::string&&)
{
std::cout<<2;
}
int main()
{
fnc ("abc");
}
All the compilers choose std::string&&
version of fnc
, and it is logical, because the temporary std::string
is created for a reference binding, but I can't find, where is it described in C++ 14 Standard.
I found one paragraph in there (3.2):
— Standard conversion sequence S1 is a better conversion sequence than standard conversion sequence S2 if
[...]
— S1 and S2 are reference bindings (8.5.3) and neither refers to an implicit object parameter of a non-static member function declared without a ref-qualifier, and S1 binds an rvalue reference to an rvalue and S2 binds an lvalue reference
But it isn't that case, because S1 binds an rvalue reference to an lvalue ("abc", lvalue of const char[4]). Where can I find description, by which the second overload is selected?
P.S. I pointed to C++14 Standard instead of C++11, because I know, that there was some defect reports in C++11, linked with rvalue reference binding.