Стандарт C++ 11 (1119564), страница 27
Текст из файла (страница 27)
Such array types can be said to bemore (or less) cv-qualified than other types based on the cv-qualification of the underlying element types.3.101<<<<<Lvalues and rvalues[basic.lval]Expressions are categorized according to the taxonomy in Figure 1.expressionglvaluelvaluervaluexvalueprvalueFigure 1 — Expression category taxonomy— An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignmentexpression) designates a function or an object. [ Example: If E is an expression of pointer type, then*E is an lvalue expression referring to the object or function to which E points. As another example,the result of calling a function whose return type is an lvalue reference is an lvalue.
— end example ]— An xvalue (an “eXpiring” value) also refers to an object, usually near the end of its lifetime (so that itsresources may be moved, for example). An xvalue is the result of certain kinds of expressions involvingrvalue references (8.3.2). [ Example: The result of calling a function whose return type is an rvaluereference is an xvalue. — end example ]— A glvalue (“generalized” lvalue) is an lvalue or an xvalue.— An rvalue (so called, historically, because rvalues could appear on the right-hand side of an assignmentexpression) is an xvalue, a temporary object (12.2) or subobject thereof, or a value that is not associatedwith an object.— A prvalue (“pure” rvalue) is an rvalue that is not an xvalue.
[ Example: The result of calling a functionwhose return type is not a reference is a prvalue. The value of a literal such as 12, 7.3e5, or true isalso a prvalue. — end example ]Every expression belongs to exactly one of the fundamental classifications in this taxonomy: lvalue, xvalue,or prvalue. This property of an expression is called its value category. [ Note: The discussion of each built-in§ 3.1078© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)operator in Clause 5 indicates the category of the value it yields and the value categories of the operands itexpects.
For example, the built-in assignment operators expect that the left operand is an lvalue and thatthe right operand is a prvalue and yield an lvalue as the result. User-defined operators are functions, andthe categories of values they expect and yield are determined by their parameter and return types. — endnote ]2Whenever a glvalue appears in a context where a prvalue is expected, the glvalue is converted to a prvalue;see 4.1, 4.2, and 4.3. [ Note: An attempt to bind an rvalue reference to an lvalue is not such a context;see 8.5.3. — end note ]3The discussion of reference initialization in 8.5.3 and of temporaries in 12.2 indicates the behavior of lvaluesand rvalues in other significant contexts.4Class prvalues can have cv-qualified types; non-class prvalues always have cv-unqualified types.
Unlessotherwise indicated (5.2.2), prvalues shall always have complete types or the void type; in addition to thesetypes, glvalues can also have incomplete types.5An lvalue for an object is necessary in order to modify the object except that an rvalue of class type canalso be used to modify its referent under certain circumstances. [ Example: a member function called for anobject (9.3) can modify the object. — end example ]6Functions cannot be modified, but pointers to functions can be modifiable.7A pointer to an incomplete type can be modifiable. At some point in the program when the pointed to typeis complete, the object at which the pointer points can also be modified.8The referent of a const-qualified expression shall not be modified (through that expression), except that ifit is of class type and has a mutable component, that component can be modified (7.1.6.1).9If an expression can be used to modify the object to which it refers, the expression is called modifiable.
Aprogram that attempts to modify an object through a nonmodifiable lvalue or rvalue expression is ill-formed.10If a program attempts to access the stored value of an object through a glvalue of other than one of thefollowing types the behavior is undefined:52— the dynamic type of the object,— a cv-qualified version of the dynamic type of the object,— a type similar (as defined in 4.4) to the dynamic type of the object,— a type that is the signed or unsigned type corresponding to the dynamic type of the object,— a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic typeof the object,— an aggregate or union type that includes one of the aforementioned types among its elements or nonstatic data members (including, recursively, an element or non-static data member of a subaggregateor contained union),— a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,— a char or unsigned char type.52) The intent of this list is to specify those circumstances in which an object may or may not be aliased.§ 3.10© ISO/IEC 2011 – All rights reserved79ISO/IEC 14882:2011(E)3.11Alignment[basic.align]1Object types have alignment requirements (3.9.1, 3.9.2) which place restrictions on the addresses at which anobject of that type may be allocated.
An alignment is an implementation-defined integer value representingthe number of bytes between successive addresses at which a given object can be allocated. An object typeimposes an alignment requirement on every object of that type; stricter alignment can be requested usingthe alignment specifier (7.6.2).2A fundamental alignment is represented by an alignment less than or equal to the greatest alignment supported by the implementation in all contexts, which is equal to alignof(std::max_align_t) (18.2). Thealignment required for a type might be different when it is used as the type of a complete object and whenit is used as the type of a subobject. [ Example:struct B { long double d; };struct D : virtual B { char c; }When D is the type of a complete object, it will have a subobject of type B, so it must be aligned appropriatelyfor a long double.
If D appears as a subobject of another object that also has B as a virtual base class, theB subobject might be part of a different subobject, reducing the alignment requirements on the D subobject.— end example ] The result of the alignof operator reflects the alignment requirement of the type in thecomplete-object case.3An extended alignment is represented by an alignment greater than alignof(std::max_align_t). It isimplementation-defined whether any extended alignments are supported and the contexts in which theyare supported (7.6.2).
A type having an extended alignment requirement is an over-aligned type. [ Note:every over-aligned type is or contains a class type to which extended alignment applies (possibly through anon-static data member). — end note ]4Alignments are represented as values of the type std::size_t. Valid alignments include only those valuesreturned by an alignof expression for the fundamental types plus an additional implementation-defined setof values, which may be empty.
Every alignment value shall be a non-negative integral power of two.5Alignments have an order from weaker to stronger or stricter alignments. Stricter alignments have largeralignment values. An address that satisfies an alignment requirement also satisfies any weaker valid alignmentrequirement.6The alignment requirement of a complete type can be queried using an alignof expression (5.3.6). Furthermore, the types char, signed char, and unsigned char shall have the weakest alignment requirement. [ Note: This enables the character types to be used as the underlying type for an aligned memoryarea (7.6.2).
— end note ]7Comparing alignments is meaningful and provides the obvious results:— Two alignments are equal when their numeric values are equal.— Two alignments are different when their numeric values are not equal.— When an alignment is larger than another it represents a stricter alignment.8[ Note: The runtime pointer alignment function (20.6.5) can be used to obtain an aligned pointer within abuffer; the aligned-storage templates in the library (20.9.7.6) can be used to obtain aligned storage.
— endnote ]9If a request for a specific extended alignment in a specific context is not supported by an implementation,the program is ill-formed. Additionally, a request for runtime allocation of dynamic storage for which therequested alignment cannot be honored shall be treated as an allocation failure.§ 3.1180© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)41Standard conversions[conv]Standard conversions are implicit conversions with built-in meaning. Clause 4 enumerates the full set of suchconversions.
A standard conversion sequence is a sequence of standard conversions in the following order:— Zero or one conversion from the following set: lvalue-to-rvalue conversion, array-to-pointer conversion,and function-to-pointer conversion.— Zero or one conversion from the following set: integral promotions, floating point promotion, integralconversions, floating point conversions, floating-integral conversions, pointer conversions, pointer tomember conversions, and boolean conversions.— Zero or one qualification conversion.[ Note: A standard conversion sequence can be empty, i.e., it can consist of no conversions.
— end note ]A standard conversion sequence will be applied to an expression if necessary to convert it to a requireddestination type.2[ Note: expressions with a given type will be implicitly converted to other types in several contexts:— When used as operands of operators. The operator’s requirements for its operands dictate the destination type (Clause 5).— When used in the condition of an if statement or iteration statement (6.4, 6.5). The destination typeis bool.— When used in the expression of a switch statement.
The destination type is integral (6.4).— When used as the source expression for an initialization (which includes use as an argument in afunction call and use as the expression in a return statement). The type of the entity being initializedis (generally) the destination type. See 8.5, 8.5.3.— end note ]3An expression e can be implicitly converted to a type T if and only if the declaration T t=e; is well-formed,for some invented temporary variable t (8.5).
Certain language constructs require that an expression beconverted to a Boolean value. An expression e appearing in such a context is said to be contextuallyconverted to bool and is well-formed if and only if the declaration bool t(e); is well-formed, for someinvented temporary variable t (8.5). The effect of either implicit conversion is the same as performing thedeclaration and initialization and then using the temporary variable as the result of the conversion. Theresult is an lvalue if T is an lvalue reference type or an rvalue reference to function type (8.3.2), an xvalueif T is an rvalue reference to object type, and a prvalue otherwise. The expression e is used as a glvalue ifand only if the initialization uses it as a glvalue.4[ Note: For user-defined types, user-defined conversions are considered as well; see 12.3.