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

  • glvalue == has identity and
  • rvalue == can be moved from .

  • So your analysis is correct because an xvalue

  • can be moved from and
  • has identity .
  • 链接地址: http://www.djcxy.com/p/72998.html

    上一篇: Xvalues与prvalues:身份属性添加了什么

    下一篇: 不是xvalues既是glvalues又rvalues?