In C++11, methods can be overloaded on whether or not the expression that denotes the object on which the method is called is an lvalue or an rvalue. If I return *this from a method called via an rvalue, do I need to explicitly move from *this or not?
Foo Foo::method() &&
{
return std::move(*this); // Is this move required or not?
}
Unfortunately, I can’t simply test this on my compiler since g++ does not support this feature yet 🙁
The type of
*thisis always an lvalue:§9.3.2 [class.this] p1§5.3.1 [expr.unary.op] p1So you will need to
std::moveif you want to invoke the move constructor.The following code snippet shows that:
Using Clang 3.1 (the only compiler I know that implements ref-qualifiers), I get the following output: