Section 9.3.2.1 of the C++ standard states:
In the body of a non-static (9.3) member function, the keyword this is a prvalue expression whose value is the address of the object for which the function is called. The type of this in a member function of a class X is X*. If the member function is declared const, the type of this is const X*, if the member function is declared volatile, the type of this is volatile X*, and if the member function is declared const volatile, the type of this is const volatile X*.
So if this
is a prvalue, what is the value category of *this
? The following suggests that even when the object is an rvalue, *this
is always an lvalue. Is this correct? Please refer to the standard, if possible.
struct F;
struct test
{
void operator()(F &&) { std::cout << "rvalue operator()" << std::endl; }
void operator()(F const &&) { std::cout << "const rvalue operator()" << std::endl; }
void operator()(F &) { std::cout << "lvalue operator()" << std::endl; }
void operator()(F const &) { std::cout << "const lvalue operator()" << std::endl; }
};
struct F
{
void operator ()()
{
struct test t;
t(*this);
}
};
int main()
{
struct F f;
f();
std::move(f)();
}
Output:
lvalue operator()
lvalue operator()