From cppreference.com

Each C++ expression (an operator with its operands, a literal, a variable name, etc.) is characterized by two independent properties: a type and a value category. Each expression has some non-reference type, and each expression belongs to exactly one of the three primary value categories: prvalue, xvalue, and lvalue.

a glvalue (“generalized” lvalue) is an expression whose evaluation determines the identity of an object, bit-field, or function;

a prvalue (“pure” rvalue) is an expression whose evaluation either

computes a value that is not associated with an object

creates a temporary object and denotes it (until C++17) computes the value of the operand of an operator or is a void expression (such prvalue has no result object ), or

), or initializes an object or a bit-field (such prvalue is said to have a result object). With the exception of decltype, all class and array prvalues have a result object even if it is discarded. The result object may be a variable, an object created by new-expression, a temporary created by temporary materialization, or a member thereof; (since C++17)

an xvalue (an “eXpiring” value) is a glvalue that denotes an object or bit-field whose resources can be reused;

an lvalue (so-called, historically, because lvalues could appear on the left-hand side of an assignment expression) is a glvalue that is not an xvalue;

an rvalue (so-called, historically, because rvalues could appear on the right-hand side of an assignment expression) is a prvalue or an xvalue.

Note: this taxonomy went through significant changes with past C++ standard revisions, see History below for details.

edit] Primary categories

edit] lvalue

The following expressions are lvalue expressions:

a function call or an overloaded operator expression, whose return type is rvalue reference to function;

a cast expression to rvalue reference to function type, such as static_cast < void ( && ) ( int ) > ( x ) . (since C++11)

Properties:

Same as glvalue (below).

Address of an lvalue may be taken by built-in address-of operator: & ++ i [1] and & std:: endl

and A modifiable lvalue may be used as the left-hand operand of the built-in assignment and compound assignment operators.

An lvalue may be used to initialize an lvalue reference; this associates a new name with the object identified by the expression.

edit] prvalue

The following expressions are prvalue expressions:

a lambda expression, such as [ ] ( int x ) { return x * x ; } ; (since C++11)

a requires-expression, such as requires ( T i ) { typename T :: type ; } ;

; a specialization of a concept, such as std :: equality_comparable < int > . (since C++20)

Properties:

Same as rvalue (below).

A prvalue cannot be polymorphic: the dynamic type of the object it denotes is always the type of the expression.

A non-class non-array prvalue cannot be cv-qualified. (Note: a function call or cast expression may result in a prvalue of non-class cv-qualified type, but the cv-qualifier is immediately stripped out.)

A prvalue cannot have incomplete type (except for type void, see below, or when used in decltype specifier)

A prvalue cannot have abstract class type or an array thereof.

edit] xvalue

The following expressions are xvalue expressions:

a function call or an overloaded operator expression, whose return type is rvalue reference to object, such as std :: move ( x ) ;

; a [ n ] , the built-in subscript expression, where one operand is an array rvalue;

, the built-in subscript expression, where one operand is an array rvalue; a. m , the member of object expression, where a is an rvalue and m is a non-static data member of non-reference type;

, the member of object expression, where is an rvalue and is a non-static data member of non-reference type; a. * mp , the pointer to member of object expression, where a is an rvalue and mp is a pointer to data member;

, the pointer to member of object expression, where is an rvalue and is a pointer to data member; a ? b : c , the ternary conditional expression for certain b and c (see definition for detail);

, the ternary conditional expression for certain and (see definition for detail); a cast expression to rvalue reference to object type, such as static_cast < char && > ( x ) ;

any expression that designates a temporary object, after temporary materialization. (since C++17)

Properties:

Same as rvalue (below).

Same as glvalue (below).

In particular, like all rvalues, xvalues bind to rvalue references, and like all glvalues, xvalues may be polymorphic, and non-class xvalues may be cv-qualified.

edit] Mixed categories

edit] glvalue

A glvalue expression is either lvalue or xvalue.

Properties:

A glvalue may be implicitly converted to a prvalue with lvalue-to-rvalue, array-to-pointer, or function-to-pointer implicit conversion.

A glvalue may be polymorphic: the dynamic type of the object it identifies is not necessarily the static type of the expression.

A glvalue can have incomplete type, where permitted by the expression.

edit] rvalue

An rvalue expression is either prvalue or xvalue.

Properties:

Address of an rvalue cannot be taken by built-in address-of operator: & int ( ) , & i ++ [3] , & 42 , and & std :: move ( x ) are invalid.

, , , and are invalid. An rvalue can't be used as the left-hand operand of the built-in assignment or compound assignment operators.

An rvalue may be used to initialize a const lvalue reference, in which case the lifetime of the object identified by the rvalue is extended until the scope of the reference ends.

An rvalue may be used to initialize an rvalue reference, in which case the lifetime of the object identified by the rvalue is extended until the scope of the reference ends.

When used as a function argument and when two overloads of the function are available, one taking rvalue reference parameter and the other taking lvalue reference to const parameter, an rvalue binds to the rvalue reference overload (thus, if both copy and move constructors are available, an rvalue argument invokes the move constructor, and likewise with copy and move assignment operators). (since C++11)

edit] Special categories

edit] Pending member function call

The expressions a.mf and p->mf, where mf is a non-static member function, and the expressions a.*pmf and p->*pmf, where pmf is a pointer to member function, are classified as prvalue expressions, but they cannot be used to initialize references, as function arguments, or for any purpose at all, except as the left-hand argument of the function call operator, e.g. (p->*pmf)(args).

edit] Void expressions

Function call expressions returning void, cast expressions to void, and throw-expressions are classified as prvalue expressions, but they cannot be used to initialize references or as function arguments. They can be used in discarded-value contexts (e.g. on a line of its own, as the left-hand operand of the comma operator, etc.) and in the return statement in a function returning void. In addition, throw-expressions may be used as the second and the third operands of the conditional operator ?:.

Void expressions have no result object. (since C++17)

edit] Bit fields

An expression that designates a bit field (e.g. a.m, where a is an lvalue of type struct A { int m: 3; }) is a glvalue expression: it may be used as the left-hand operand of the assignment operator, but its address cannot be taken and a non-const lvalue reference cannot be bound to it. A const lvalue reference or rvalue reference can be initialized from a bit-field glvalue, but a temporary copy of the bit-field will be made: it won't bind to the bit field directly.

edit] History

edit] CPL

The programming language CPL was first to introduce value categories for expressions: all CPL expressions can be evaluated in "right-hand mode", but only certain kinds of expression are meaningful in "left-hand mode". When evaluated in right-hand mode, an expression is regarded as being a rule for the computation of a value (the right-hand value, or rvalue). When evaluated in left-hand mode an expression effectively gives an address (the left-hand value, or lvalue). "Left" and "Right" here stood for "left of assignment" and "right of assignment".

edit] C

The C programming language followed a similar taxonomy, except that the role of assignment was no longer significant: C expressions are categorized between "lvalue expressions" and others (functions and non-object values), where "lvalue" means an expression that identifies an object, a "locator value"[4].

Pre-2011 C++ followed the C model, but restored the name "rvalue" to non-lvalue expressions, made functions into lvalues, and added the rule that references can bind to lvalues, but only references to const can bind to rvalues. Several non-lvalue C expressions became lvalue expressions in C++.

With the introduction of move semantics in C++11, value categories were redefined to characterize two independent properties of expressions[5]:

has identity : it's possible to determine whether the expression refers to the same entity as another expression, such as by comparing addresses of the objects or the functions they identify (obtained directly or indirectly);

: it's possible to determine whether the expression refers to the same entity as another expression, such as by comparing addresses of the objects or the functions they identify (obtained directly or indirectly); can be moved from: move constructor, move assignment operator, or another function overload that implements move semantics can bind to the expression.

In C++11, expressions that:

have identity and cannot be moved from are called lvalue expressions;

expressions; have identity and can be moved from are called xvalue expressions;

expressions; do not have identity and can be moved from are called prvalue ("pure rvalue") expressions;

("pure rvalue") expressions; do not have identity and cannot be moved from are not used[6].

The expressions that have identity are called "glvalue expressions" (glvalue stands for "generalized lvalue"). Both lvalues and xvalues are glvalue expressions.

The expressions that can be moved from are called "rvalue expressions". Both prvalues and xvalues are rvalue expressions.

In C++17, copy elision was made mandatory in some situations, and that required separation of prvalue expressions from the temporary objects initialized by them, resulting in the system we have today. Note that, in contrast with the C++11 scheme, prvalues are no longer moved from.

↑ i has built-in type or the pre-increment operator is Assuminghas built-in type or the pre-increment operator is overloaded to return by lvalue reference. 2.0 2.1 2.2 2.3 Special rvalue category, see pending member function call ↑ i has built-in type or the postincrement operator is not Assuminghas built-in type or the postincrement operator is not overloaded to return by lvalue reference. ↑ "A difference of opinion within the C community centered around the meaning of lvalue, one group considering an lvalue to be any kind of object locator, another group holding that an lvalue is meaningful on the left side of an assigning operator. The C89 Committee adopted the definition of lvalue as an object locator." -- ANSI C Rationale, 6.3.2.1/10. ↑ "New" Value Terminology by Bjarne Stroustrup, 2010. ↑ const prvalues (only allowed for class types) and const xvalues do not bind to T&& overloads, but they bind to the const T&& overloads, which are also classified as "move constructor" and "move assignment operator" by the standard, satisfying the definition of "can be moved from" for the purpose of this classification. However, such overloads cannot modify their arguments and are not used in practice; in their absence const prvalues and const xvalues bind to const T& overloads.

edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior CWG 616 C++11 member access and member access through pointer to member of an rvalue resulted in prvalue reclassified as xvalue CWG 1213 C++11 subscripting an array rvalue resulted in lvalue reclassified as xvalue

edit] See also