An rvalue
is a type of expression, not a type of object. We're talking about the temporary object created by Contrived()
, it doesn't make sense to say "this object is an rvalue". The expression that created the object is an rvalue expression, but that's different.
Even though the object in question is a temporary object, its lifetime has been extended. It's perfectly fine to perform operations on the object using the identifier r
which denotes it. The expression r
is an lvalue.
p1
is OK. On the p2
and p3
lines, the lifetime of the reference ends at the end of that full-expression, so the temporary object's lifetime also ends at that point. So it would be undefined behaviour to use p2
or p3
on subsequent lines. The initializing expression could be used as an argument to a function call though, if that's what you meant.