Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this expression an lvalue or an rvalue?

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 =.

like image 347
João Paulo Avatar asked Dec 31 '22 23:12

João Paulo


1 Answers

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.

like image 91
Paul Evans Avatar answered Jan 12 '23 09:01

Paul Evans