From this link, it says that
Objects, references, functions including function template specializations, and expressions have a property called type
<
Does
rf_int
have a reference type or not?
The entity (or variable) with the name rf_int
has type int&&
(a reference type) because of the way it is declared, but the expression rf_int
has type int
(a non-reference type) per [expr]/5:
If an expression initially has the type “reference to
T
” ([dcl.ref], [dcl.init.ref]), the type is adjusted toT
prior to any further analysis. The expression designates the object or function denoted by the reference, and the expression is an lvalue or an xvalue, depending on the expression. [ Note: Before the lifetime of the reference has started or after it has ended, the behavior is undefined (see [basic.life]). — end note ]
Do we have to provide context when talking about the type of a name, be it a variable or an expression?
Yes, we do. rf_int
can be said to have different types depending on whether it refers to the entity or the expression.
More specifically, when a variable name is used in function call:
SomeFunc(rf_int);
Is
rf_int
now considered an expression (thus it is an lvalue with typeint
), or a variable (thus it is an lvalue with type rvalue reference toint
)?
It is considered an expression, which is an lvalue of type int
. (Note that value category is a property of expressions. It is not correct to say a variable is an lvalue.)