Aren't xvalues both glvalues and rvalues?
I read this answer the part that caught my attention was this:
int i;
int* p = &i;
int& f();
int&& g();
int h();
h() // prvalue
g() // glvalue (xvalue)
f() // glvalue (lvalue)
i // glvalue (lvalue)
*p // glvalue (lvalue)
std::move(i) // glvalue (xvalue)
and with this chart in mind
I got confused.
If a glvalue is either an lvalue or an xvalue and an rvalue is either a prvalue or an xvalue, isn't it wrong to say that g()
is a glvalue without saying that it is also an rvalue? The same with std::move(i)
.
What my version of the above code would look like:
h() // rvalue (prvalue)
g() // glvalue and rvalue (xvalue)
f() // glvalue (lvalue)
i // glvalue (lvalue)
*p // glvalue (lvalue)
std::move(i) // glvalue and rvalue(xvalue)
As for what the standard says(I only quote the most related parts):
An rvalue (so-called, historically, because rvalues could appear on the right-hand side of an assignment expression) is an xvalue
and
A glvalue (“generalized” lvalue) is an lvalue or an xvalue.
Of course, I could be wrong. If so, please help me out a little :)
If a glvalue is either an lvalue or an xvalue and an rvalue is either a prvalue or an xvalue, isn't it wrong to say that g() is a glvalue without saying that it is also an rvalue?
Yes.
If g()
is an xvalue, then it is both a glvalue and an rvalue.
As I understand it from here
So your analysis is correct because an xvalue