class A{};
A retA() {return A();}
int main()
{
retA() = A(); // no compile error in MS VS2012 and GCC 4.8.1
return 0;
}
I think that "retA()" must return a temporary object, but, in this sample code, it is used as a lvalue.
why? can anyone help me? thanks.
They do not say that a temporary object is an rvalue. Objects do not have value categories, that's a property of expressions. There's a slightly more detailed (I hope) exposition at http://en.cppreference.com/w/cpp/language/value_category
The expression retA() is indeed an rvalue expression (because it is a function call expression to a value-returning function).
In the expression retA() = A(), it is not used as a lvalue. To use it as lvalue, try to take its address: &retA()