Стандарт C++ 98 (1119566), страница 30
Текст из файла (страница 30)
The process for determining whether an operand expression E1 of type T1 can be converted to match an operand expression E2of type T2 is defined as follows:— If E2 is an lvalue: E1 can be converted to match E2 if E1 can be implicitly converted (clause 4) to thetype “reference to T2”, subject to the constraint that in the conversion the reference must bind directly(8.5.3) to E1.— If E2 is an rvalue, or if the conversion above cannot be done:— if E1 and E2 have class type, and the underlying class types are the same or one is a base class ofthe other: E1 can be converted to match E2 if the class of T2 is the same type as, or a base class of,the class of T1, and the cv-qualification of T2 is the same cv-qualification as, or a greater cvqualification than, the cv-qualification of T1.
If the conversion is applied, E1 is changed to anrvalue of type T2 that still refers to the original source class object (or the appropriate subobjectthereof). [Note: that is, no copy is made. ]— Otherwise (i.e., if E1 or E2 has a nonclass type, or if they both have class types but the underlying88© ISO/IECISO/IEC 14882:1998(E)5 Expressions5.16 Conditional operatorclasses are not either the same or one a base class of the other): E1 can be converted to match E2 ifE1 can be implicitly converted to the type that expression E2 would have if E2 were converted to anrvalue (or the type it has, if E2 is an rvalue).Using this process, it is determined whether the second operand can be converted to match the thirdoperand, and whether the third operand can be converted to match the second operand.
If both can be converted, or one can be converted but the conversion is ambiguous, the program is ill-formed. If neither canbe converted, the operands are left unchanged and further checking is performed as described below. Ifexactly one conversion is possible, that conversion is applied to the chosen operand and the convertedoperand is used in place of the original operand for the remainder of this section.4If the second and third operands are lvalues and have the same type, the result is of that type and is anlvalue.5Otherwise, the result is an rvalue. If the second and third operand do not have the same type, and either has(possibly cv-qualified) class type, overload resolution is used to determine the conversions (if any) to beapplied to the operands (13.3.1.2, 13.6). If the overload resolution fails, the program is ill-formed.
Otherwise, the conversions thus determined are applied, and the converted operands are used in place of the original operands for the remainder of this section.6Lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are performed on the second and third operands. After those conversions, one of the following shall hold:— The second and third operands have the same type; the result is of that type.— The second and third operands have arithmetic or enumeration type; the usual arithmetic conversionsare performed to bring them to a common type, and the result is of that type.— The second and third operands have pointer type, or one has pointer type and the other is a null pointerconstant; pointer conversions (4.10) and qualification conversions (4.4) are performed to bring them totheir composite pointer type (5.9).
The result is of the composite pointer type.— The second and third operands have pointer to member type, or one has pointer to member type and theother is a null pointer constant; pointer to member conversions (4.11) and qualification conversions(4.4) are performed to bring them to a common type, whose cv-qualification shall match the cvqualification of either the second or the third operand. The result is of the common type.5.17 Assignment operators1[expr.ass]There are several assignment operators, all of which group right-to-left.
All require a modifiable lvalue astheir left operand, and the type of an assignment expression is that of its left operand. The result of theassignment operation is the value stored in the left operand after the assignment has taken place; the resultis an lvalue.assignment-expression:conditional-expressionlogical-or-expression assignment-operator assignment-expressionthrow-expressionassignment-operator: one of= *= /= %=+=-=>>=<<=&=^=|=2In simple assignment (=), the value of the expression replaces that of the object referred to by the leftoperand.3If the left operand is not of class type, the expression is implicitly converted (clause 4) to the cv-unqualifiedtype of the left operand.4If the left operand is of class type, the class shall be complete.
Assignment to objects of a class is definedby the copy assignment operator (12.8, 13.5.3).89ISO/IEC 14882:1998(E)5.17 Assignment operators© ISO/IEC5 Expressions5[Note: For class objects, assignment is not in general the same as initialization (8.5, 12.1, 12.6, 12.8). ]6When the left operand of an assignment operator denotes a reference to T, the operation assigns to theobject of type T denoted by the reference.7The behavior of an expression of the form E1 op= E2 is equivalent to E1 = E1 op E2 except that E1 isevaluated only once.
In += and -=, E1 shall either have arithmetic type or be a pointer to a possibly cvqualified completely defined object type. In all other cases, E1 shall have arithmetic type.8If the value being stored in an object is accessed from another object that overlaps in any way the storage ofthe first object, then the overlap shall be exact and the two objects shall have the same type, otherwise thebehavior is undefined.5.18 Comma operator1[expr.comma]The comma operator groups left-to-right.expression:assignment-expressionexpression , assignment-expressionA pair of expressions separated by a comma is evaluated left-to-right and the value of the left expression isdiscarded.
The lvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are not applied to the left expression. All side effects (1.9) of the left expression, except for thedestruction of temporaries (12.2), are performed before the evaluation of the right expression. The type andvalue of the result are the type and value of the right operand; the result is an lvalue if its right operand is.2In contexts where comma is given a special meaning, [Example: in lists of arguments to functions (5.2.2)and lists of initializers (8.5) ] the comma operator as described in clause 5 can appear only in parentheses.[Example:f(a, (t=3, t+2), c);has three arguments, the second of which has the value 5. ]5.19 Constant expressions1[expr.const]In several places, C++ requires expressions that evaluate to an integral or enumeration constant: as arraybounds (8.3.4, 5.3.4), as case expressions (6.4.2), as bit-field lengths (9.6), as enumerator initializers (7.2),as static member initializers (9.4.2), and as integral or enumeration non-type template arguments (14.3).constant-expression:conditional-expressionAn integral constant-expression can involve only literals (2.13), enumerators, const variables or staticdata members of integral or enumeration types initialized with constant expressions (8.5), non-type template parameters of integral or enumeration types, and sizeof expressions.
Floating literals (2.13.3) canappear only if they are cast to integral or enumeration types. Only type conversions to integral or enumeration types can be used. In particular, except in sizeof expressions, functions, class objects, pointers, orreferences shall not be used, and assignment, increment, decrement, function-call, or comma operators shallnot be used.2Other expressions are considered constant-expressions only for the purpose of non-local static objectinitialization (3.6.2). Such constant expressions shall evaluate to one of the following:— a null pointer value (4.10),— a null member pointer value (4.11),— an arithmetic constant expression,— an address constant expression,— a reference constant expression,90© ISO/IEC5 ExpressionsISO/IEC 14882:1998(E)5.19 Constant expressions— an address constant expression for a complete object type, plus or minus an integral constant expression,or— a pointer to member constant expression.3An arithmetic constant expression shall have arithmetic or enumeration type and shall only have operandsthat are integer literals (2.13.1), floating literals (2.13.3), enumerators, character literals (2.13.2) andsizeof expressions (5.3.3).
Cast operators in an arithmetic constant expression shall only convert arithmetic or enumeration types to arithmetic or enumeration types, except as part of an operand to the sizeofoperator.4An address constant expression is a pointer to an lvalue designating an object of static storage duration, astring literal (2.13.4), or a function. The pointer shall be created explicitly, using the unary & operator, orimplicitly using a non-type template parameter of pointer type, or using an expression of array (4.2) orfunction (4.3) type.
The subscripting operator [] and the class member access . and -> operators, the &and * unary operators, and pointer casts (except dynamic_casts, 5.2.7) can be used in the creation of anaddress constant expression, but the value of an object shall not be accessed by the use of these operators.If the subscripting operator is used, one of its operands shall be an integral constant expression.