Say I have the following functions:
void f2(int&& i)
{
puts("f2(int&& i)");
}
void f(int&& i)
{
puts("f(int&& i)");
f2(i);
}
The compiler error emitted is:
error C2664: 'void f2(int &&)': cannot convert argument 1 from 'int' to 'int &&'
message : You cannot bind an lvalue to an rvalue reference
It works if you cast to int&&
again with another call to std::move()
:
void f(int&& i)
{
puts("f(int&& i)");
f2(std::move(i));
}
But that shouldn't be necessary should it? It looks to me that the variable received by f(int&& i)
is an xvalue. If f
receives int&&
, so we should just be able to pass that along, no?
How is the int&&
received by f
still an lvalue?