Movatterモバイル変換


[0]ホーム

URL:


7 Expressions[expr]

7.2 Properties of expressions[expr.prop]

7.2.1 Value category[basic.lval]

Expressions are categorized according to the taxonomy in Figure2.
categoriesexpressionexpressionglvalueglvalueexpression->glvaluervaluervalueexpression->rvaluelvaluelvalueglvalue->lvaluexvaluexvalueglvalue->xvaluervalue->xvalueprvalueprvaluervalue->prvalue
Figure2 — Expression category taxonomy  [fig:basic.lval]
  • Aglvalue is an expressionwhose evaluation determines the identity ofan object, function, non-static data member, ora direct base class relationship.
  • Aprvalue is an expression whose evaluation initializes an objector computes the value of an operand of an operator,as specified by the context in which it appears,or an expression that has typecvvoid.
  • Anxvalue is a glvalue that denotes an object whose resources can be reused (usually because it is near the end of its lifetime).
  • Anlvalue is a glvalue that is not an xvalue.
  • Anrvalue is a prvalue or an xvalue.
Every expression belongs to exactly one of the fundamental categories in thistaxonomy: lvalue, xvalue, or prvalue.
This property of an expression is calleditsvalue category.
[Note 1: 
The discussion of each built-in operator in[expr.compound] indicates the category of the value it yields and the value categoriesof the operands it expects.
For example, the built-in assignment operators expect thatthe left operand is an lvalue and that the right operand is a prvalue and yield anlvalue as the result.
User-defined operators are functions, and the categories ofvalues they expect and yield are determined by their parameter and return types.
— end note]
[Note 2: 
Historically, lvalues and rvalues were so-calledbecause they could appear on the left- and right-hand side of an assignment(although this is no longer generally true);glvalues are “generalized” lvalues,prvalues are “pure” rvalues,and xvalues are “eXpiring” lvalues.
Despite their names, these terms apply to expressions, not values.
— end note]
[Note 3: 
An expression is an xvalue if it is:
In general, the effect of this rule is that named rvalue references aretreated as lvalues and unnamed rvalue references to objects are treated asxvalues; rvalue references to functions are treated as lvalues whether named or not.
— end note]
[Example 1: struct A{int m;};A&&operator+(A, A);A&& f();A a;A&& ar=static_cast<A&&>(a);
The expressionsf(),f().m,static_cast<A&&>(a), anda+ aare xvalues.
The expressionar is an lvalue.
— end example]
Theresult of a glvalue is the entity denoted by the expression.
Theresult of a prvalueis the value that the expression stores into its context;a prvalue that has typecvvoid has no result.
A prvalue whose result is the valueVis sometimes said to have or name the valueV.
Theresult object of a prvalue is the object initialized by the prvalue;a prvalue that has typecvvoidhas no result object.
[Note 4: 
Except when the prvalue is the operand of adecltype-specifier,a prvalue of object type always has a result object.
For a discarded prvalue that has type other thancvvoid,a temporary object is materialized; see[expr.context].
— end note]
Whenever a glvalue appears as an operand of an operator thatrequires a prvalue for that operand, thelvalue-to-rvalue ([conv.lval]), array-to-pointer ([conv.array]),or function-to-pointer ([conv.func]) standard conversions areapplied to convert the expression to a prvalue.
[Note 5: 
An attempt to bind an rvalue reference to an lvalue is not such a context; see[dcl.init.ref].
— end note]
[Note 6: 
Because cv-qualifiers are removed from the type of an expression ofnon-class type when the expression is converted to a prvalue, an lvalueof typeconstint can, for example, be used wherea prvalue of typeint is required.
— end note]
[Note 7: 
There are no prvalue bit-fields; if a bit-field is converted to aprvalue ([conv.lval]), a prvalue of the type of the bit-field iscreated, which might then be promoted ([conv.prom]).
— end note]
Unless otherwise specified ([expr.reinterpret.cast],[expr.const.cast]),whenever a prvaluethat is not the result of the lvalue-to-rvalue conversion ([conv.lval])appears as an operand of an operator,thetemporary materialization conversion isapplied to convert the expression to an xvalue.
[Note 8: 
The discussion of reference initialization in[dcl.init.ref] and oftemporaries in[class.temporary] indicates the behavior of lvaluesand rvalues in other significant contexts.
— end note]
Unless otherwise indicated ([dcl.type.decltype]),a prvalue shall always have complete type or thevoid type;if it has a class type or (possibly multidimensional) array of class type,that class shall not be an abstract class ([class.abstract]).
A glvalue shall not have typecvvoid.
[Note 9: 
A glvalue can have complete or incomplete non-void type.
Class and array prvalues can have cv-qualified types; other prvaluesalways have cv-unqualified types.
— end note]
An lvalue ismodifiable unless its type is const-qualifiedor is a function type.
[Note 10: 
A program that attemptsto modify an object through a nonmodifiable lvalue or through an rvalueis ill-formed ([expr.assign],[expr.post.incr],[expr.pre.incr]).
— end note]
An object of dynamic type istype-accessible through a glvalue of typeif is similar ([conv.qual]) to:
  • ,
  • a type that is the signed or unsigned type corresponding to, or
  • achar,unsignedchar, orstd​::​byte type.
If a program attempts to access ([defns.access])the stored value of an object through a glvaluethrough which it is not type-accessible,the behavior is undefined.38
If a program invokesa defaulted copy/move constructor or copy/move assignment operatorfor a union of typeU with a glvalue argumentthat does not denote an object of typecvU within its lifetime,the behavior is undefined.
[Note 11: 
In C, an entire object of structure type can be accessed, e.g., using assignment.
By contrast, C++ has no notion of accessing an object of class typethrough an lvalue of class type.
— end note]
38)38)
The intent of this list is to specify those circumstances in which anobject can or cannot be aliased.

[8]ページ先頭

©2009-2026 Movatter.jp