4

Look at this expression:

T t;    
T& ref = t;

The ref expression is an lvalue or an rvalue? I believe it's an rvalue because ref does not "designates a function or an object":

"An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignment expression) designates a function or an object."

[open-std draft n3092]

According to cppreference, a reference is not a object.

"The following entities are not objects: value, reference [...]"

I'm in doubt, because ref is in the left side of =.

João Paulo
  • 5,109
  • 3
  • 37
  • 64
  • 8
    `ref` itself, as an entity, is not an object. Nevertheless, *expression* `ref` does designate an object. Don't mix the entity itself and the *expression* consisting solely of that entity's name. These are different things, which are treated differently. – AnT May 13 '19 at 16:28
  • @tadman I'm not using class objects definition. See the cppreference link I let there. – João Paulo May 13 '19 at 16:30
  • @AnT Which object the expression `ref` designates? That's what I'm not understanding. Would the object be `t`, once `ref` is an alias for it? – João Paulo May 13 '19 at 16:32
  • Dup? Or related? https://stackoverflow.com/questions/3601602/what-are-rvalues-lvalues-xvalues-glvalues-and-prvalues – Eljay May 13 '19 at 16:38
  • It's an lvalue reference to an object of T. https://en.cppreference.com/w/cpp/language/reference – doug May 13 '19 at 16:42
  • @LightnessRacesinOrbit Yeah, it's a more nuanced term than that and I think AnT did a better job of explaining. – tadman May 13 '19 at 17:58

2 Answers2

5

I'm in doubt, because ref is in the left side of =.

ref is a name and therefore an lvalue.

I believe it's an rvalue because ref does not "designates a function or an object"

It designates the same object as t does.

Paul Evans
  • 26,111
  • 3
  • 30
  • 50
4

A reference does designate a function or object! It is literally written like that in the standard! See in [expr.type]/1:

If an expression initially has the type “reference to T” ([dcl.ref], [dcl.init.ref]), the type is adjusted to T prior to any further analysis. The expression designates the object or function denoted by the reference,[...]

Oliv
  • 16,492
  • 1
  • 24
  • 63