The C++11 and C++14 standard (and working draft, respectively) say in §3.10.1:
A prvalue (“pure” rvalue) is an rvalue that is not an xvalue. [Example: The result of calling a function whose return type is not a reference is a prvalue. The value of a literal such as 12, 7.3e5, or true is also a prvalue. —end example ]
and
An rvalue (so called, historically, because rvalues could appear on the right-hand side of an assignment expression) is an xvalue, a temporary object (12.2) or subobject thereof, or a value that is not associated with an object.
Which leads me to the question: How can an expression be "a value not associated with an object"?
I was under the impression, that it is the purpose of expressions to return objects or void
(which I do not expect to be a value either).
Is there some simple and common example for such expressions?
Edit 1
To further complicate things, consider the following:
int const& x = 3;
int&& y = 4;
In context of §8.3.2.5, which contains the most interesting snippet:
[...] A reference shall be initialized to refer to a valid object or function [...]
Which is reinforced by §8.5.3.1:
A variable declared to be a T& or T&&, that is, “reference to type T” (8.3.2), shall be initialized by an object, or function, of type T or by an object that can be converted into a T. [...]
[intro.object]
:
The constructs in a C++ program create, destroy, refer to, access, and manipulate objects. An object is a region of storage. [ Note: A function is not an object, regardless of whether or not it occupies storage in the way that objects do. —end note ] An object is created by a definition (3.1), by a new-expression (5.3.4) or by the implementation (12.2) when needed.
So "a value not associated with an object" is something created not by definition or with new-expression, which also means that it doesn't have corresponding region of storage, like for example a literal.
Edit: Except string literals (see comments)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With