Стандарт C++ 11 (1119564), страница 28
Текст из файла (страница 28)
In general, animplicit conversion sequence (13.3.3.1) consists of a standard conversion sequence followed by a user-definedconversion followed by another standard conversion sequence. — end note ]5[ Note: There are some contexts where certain conversions are suppressed. For example, the lvalue-torvalue conversion is not done on the operand of the unary & operator. Specific exceptions are given in thedescriptions of those operators and contexts. — end note ]© ISO/IEC 2011 – All rights reserved81ISO/IEC 14882:2011(E)4.1Lvalue-to-rvalue conversion[conv.lval]1A glvalue (3.10) of a non-function, non-array type T can be converted to a prvalue.53 If T is an incompletetype, a program that necessitates this conversion is ill-formed.
If the object to which the glvalue refers is notan object of type T and is not an object of a type derived from T, or if the object is uninitialized, a programthat necessitates this conversion has undefined behavior. If T is a non-class type, the type of the prvalue isthe cv-unqualified version of T. Otherwise, the type of the prvalue is T.542When an lvalue-to-rvalue conversion occurs in an unevaluated operand or a subexpression thereof (Clause 5)the value contained in the referenced object is not accessed. Otherwise, if the glvalue has a class type,the conversion copy-initializes a temporary of type T from the glvalue and the result of the conversion is aprvalue for the temporary.
Otherwise, if the glvalue has (possibly cv-qualified) type std::nullptr_t, theprvalue result is a null pointer constant (4.10). Otherwise, the value contained in the object indicated bythe glvalue is the prvalue result.3[ Note: See also 3.10. — end note ]4.21Array-to-pointer conversion[conv.array]An lvalue or rvalue of type “array of N T” or “array of unknown bound of T” can be converted to a prvalueof type “pointer to T”.
The result is a pointer to the first element of the array.4.3Function-to-pointer conversion[conv.func]1An lvalue of function type T can be converted to a prvalue of type “pointer to T.” The result is a pointer tothe function.552[ Note: See 13.4 for additional rules for the case where the function is overloaded. — end note ]4.4Qualification conversions[conv.qual]1A prvalue of type “pointer to cv1 T” can be converted to a prvalue of type “pointer to cv2 T” if “cv2 T” ismore cv-qualified than “cv1 T”.2A prvalue of type “pointer to member of X of type cv1 T” can be converted to a prvalue of type “pointer tomember of X of type cv2 T” if “cv2 T” is more cv-qualified than “cv1 T”.3[ Note: Function types (including those used in pointer to member function types) are never cv-qualified (8.3.5).— end note ]4A conversion can add cv-qualifiers at levels other than the first in multi-level pointers, subject to the followingrules:56Two pointer types T1 and T2 are similar if there exists a type T and integer n > 0 such that:T1 is cv 1,0 pointer to cv 1,1 pointer to · · · cv 1,n−1 pointer to cv 1,n TandT2 is cv 2,0 pointer to cv 2,1 pointer to · · · cv 2,n−1 pointer to cv 2,n T53) For historical reasons, this conversion is called the “lvalue-to-rvalue” conversion, even though that name does not accuratelyreflect the taxonomy of expressions described in 3.10.54) In C++ class prvalues can have cv-qualified types (because they are objects).
This differs from ISO C, in which non-lvaluesnever have cv-qualified types.55) This conversion never applies to non-static member functions because an lvalue that refers to a non-static member functioncannot be obtained.56) These rules ensure that const-safety is preserved by the conversion.§ 4.482© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)where each cv i,j is const, volatile, const volatile, or nothing. The n-tuple of cv-qualifiers after thefirst in a pointer type, e.g., cv 1,1 , cv 1,2 , · · · , cv 1,n in the pointer type T1, is called the cv-qualificationsignature of the pointer type.
An expression of type T1 can be converted to type T2 if and only if thefollowing conditions are satisfied:— the pointer types are similar.— for every j > 0, if const is in cv 1,j then const is in cv 2,j , and similarly for volatile.— if the cv 1,j and cv 2,j are different, then const is in every cv 2,k for 0 < k < j.[ Note: if a program could assign a pointer of type T** to a pointer of type const T** (that is, if line #1below were allowed), a program could inadvertently modify a const object (as it is done on line #2). Forexample,int main() {const char c = ’c’;char* pc;const char** pcc = &pc;*pcc = &c;*pc = ’C’;}// #1: not allowed// #2: modifies a const object— end note ]5A multi-level pointer to member type, or a multi-level mixed pointer and pointer to member type has theform:cv 0 P0 to cv 1 P1 to · · · cv n−1 Pn−1 to cv n Twhere Pi is either a pointer or pointer to member and where T is not a pointer type or pointer to membertype.6Two multi-level pointer to member types or two multi-level mixed pointer and pointer to member types T1and T2 are similar if there exists a type T and integer n > 0 such that:T1 is cv 1,0 P0 to cv 1,1 P1 to · · · cv 1,n−1 Pn−1 to cv 1,n TandT2 is cv 2,0 P0 to cv 2,1 P1 to · · · cv 2,n−1 Pn−1 to cv 2,n T7For similar multi-level pointer to member types and similar multi-level mixed pointer and pointer to membertypes, the rules for adding cv-qualifiers are the same as those used for similar pointer types.4.5Integral promotions[conv.prom]1A prvalue of an integer type other than bool, char16_t, char32_t, or wchar_t whose integer conversionrank (4.13) is less than the rank of int can be converted to a prvalue of type int if int can represent allthe values of the source type; otherwise, the source prvalue can be converted to a prvalue of type unsignedint.2A prvalue of type char16_t, char32_t, or wchar_t (3.9.1) can be converted to a prvalue of the first ofthe following types that can represent all the values of its underlying type: int, unsigned int, long int,unsigned long int, long long int, or unsigned long long int.
If none of the types in that list canrepresent all the values of its underlying type, a prvalue of type char16_t, char32_t, or wchar_t can beconverted to a prvalue of its underlying type.§ 4.5© ISO/IEC 2011 – All rights reserved83ISO/IEC 14882:2011(E)3A prvalue of an unscoped enumeration type whose underlying type is not fixed (7.2) can be converted to aprvalue of the first of the following types that can represent all the values of the enumeration (i.e., the valuesin the range bmin to bmax as described in 7.2): int, unsigned int, long int, unsigned long int, longlong int, or unsigned long long int. If none of the types in that list can represent all the values ofthe enumeration, a prvalue of an unscoped enumeration type can be converted to a prvalue of the extendedinteger type with lowest integer conversion rank (4.13) greater than the rank of long long in which all thevalues of the enumeration can be represented.
If there are two such extended types, the signed one is chosen.4A prvalue of an unscoped enumeration type whose underlying type is fixed (7.2) can be converted to aprvalue of its underlying type. Moreover, if integral promotion can be applied to its underlying type, aprvalue of an unscoped enumeration type whose underlying type is fixed can also be converted to a prvalueof the promoted underlying type.5A prvalue for an integral bit-field (9.6) can be converted to a prvalue of type int if int can represent allthe values of the bit-field; otherwise, it can be converted to unsigned int if unsigned int can representall the values of the bit-field. If the bit-field is larger yet, no integral promotion applies to it. If the bit-fieldhas an enumerated type, it is treated as any other value of that type for promotion purposes.6A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and truebecoming one.7These conversions are called integral promotions.4.6Floating point promotion[conv.fpprom]1A prvalue of type float can be converted to a prvalue of type double.