Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "a value not associated with an object"?

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. [...]

like image 331
gha.st Avatar asked Sep 04 '14 20:09

gha.st


1 Answers

[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)

like image 100
Anton Savin Avatar answered Oct 04 '22 02:10

Anton Savin