Стандарт C++ 11 (1119564), страница 33
Текст из файла (страница 33)
[ Note: Such initializations are indeterminately sequenced with respect to each other (1.9) —end note ] If the function is a non-static member function, the this parameter of the function (9.3.2) shallbe initialized with a pointer to the object of the call, converted as if by an explicit type conversion (5.4).[ Note: There is no access or ambiguity checking on this conversion; the access checking and disambiguation62) This is true even if the subscript operator is used in the following common idiom: &x[0].63) A static member function (9.4) is an ordinary function.§ 5.2.298© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)are done as part of the (possibly implicit) class member access operator.
See 10.2, 11.2, and 5.2.5. —end note ] When a function is called, the parameters that have object type shall have completely-definedobject type. [ Note: this still allows a parameter to be a pointer or reference to an incomplete class type.However, it prevents a passed-by-value parameter to have an incomplete class type. — end note ] Duringthe initialization of a parameter, an implementation may avoid the construction of extra temporaries bycombining the conversions on the associated argument and/or the construction of temporaries with theinitialization of the parameter (see 12.2).
The lifetime of a parameter ends when the function in which itis defined returns. The initialization and destruction of each parameter occurs within the context of thecalling function. [ Example: the access of the constructor, conversion functions or destructor is checked atthe point of call in the calling function. If a constructor or destructor for a function parameter throws anexception, the search for a handler starts in the scope of the calling function; in particular, if the functioncalled has a function-try-block (Clause 15) with a handler that could handle the exception, this handler isnot considered.
— end example ] The value of a function call is the value returned by the called functionexcept in a virtual function call if the return type of the final overrider is different from the return type ofthe statically chosen function, the value returned from the final overrider is converted to the return type ofthe statically chosen function.5[ Note: a function can change the values of its non-const parameters, but these changes cannot affect thevalues of the arguments except where a parameter is of a reference type (8.3.2); if the reference is to aconst-qualified type, const_cast is required to be used to cast away the constness in order to modifythe argument’s value.
Where a parameter is of const reference type a temporary object is introduced ifneeded (7.1.6, 2.14, 2.14.5, 8.3.4, 12.2). In addition, it is possible to modify the values of nonconstant objectsthrough pointer parameters. — end note ]6A function can be declared to accept fewer arguments (by declaring default arguments (8.3.6)) or morearguments (by using the ellipsis, ..., or a function parameter pack (8.3.5)) than the number of parametersin the function definition (8.4).
[ Note: this implies that, except where the ellipsis (...) or a functionparameter pack is used, a parameter is available for each argument. — end note ]7When there is no parameter for a given argument, the argument is passed in such a way that the receivingfunction can obtain the value of the argument by invoking va_arg (18.10). [ Note: This paragraph does notapply to arguments passed to a function parameter pack. Function parameter packs are expanded duringtemplate instantiation (14.5.3), thus each such argument has a corresponding parameter when a functiontemplate specialization is actually called.
— end note ] The lvalue-to-rvalue (4.1), array-to-pointer (4.2), andfunction-to-pointer (4.3) standard conversions are performed on the argument expression. An argument thathas (possibly cv-qualified) type std::nullptr_t is converted to type void* (4.10). After these conversions,if the argument does not have arithmetic, enumeration, pointer, pointer to member, or class type, theprogram is ill-formed.
Passing a potentially-evaluated argument of class type (Clause 9) having a nontrivial copy constructor, a non-trivial move contructor, or a non-trivial destructor, with no correspondingparameter, is conditionally-supported with implementation-defined semantics.
If the argument has integralor enumeration type that is subject to the integral promotions (4.5), or a floating point type that is subjectto the floating point promotion (4.6), the value of the argument is converted to the promoted type beforethe call. These promotions are referred to as the default argument promotions.8[ Note: The evaluations of the postfix expression and of the argument expressions are all unsequencedrelative to one another.
All side effects of argument expression evaluations are sequenced before the functionis entered (see 1.9). — end note ]9Recursive calls are permitted, except to the function named main (3.6.1).10A function call is an lvalue if the result type is an lvalue reference type or an rvalue reference to functiontype, an xvalue if the result type is an rvalue reference to object type, and a prvalue otherwise.11If a function call is a prvalue of object type:§ 5.2.2© ISO/IEC 2011 – All rights reserved99ISO/IEC 14882:2011(E)— if the function call is either— the operand of a decltype-specifier or— the right operand of a comma operator that is the operand of a decltype-specifier,a temporary object is not introduced for the prvalue.
The type of the prvalue may be incomplete.[ Note: as a result, storage is not allocated for the prvalue and it is not destroyed; thus, a class type isnot instantiated as a result of being the type of a function call in this context. This is true regardless ofwhether the expression uses function call notation or operator notation (13.3.1.2).
— end note ] [ Note:unlike the rule for a decltype-specifier that considers whether an id-expression is parenthesized (7.1.6.2),parentheses have no special meaning in this context. — end note ]— otherwise, the type of the prvalue shall be complete.5.2.3Explicit type conversion (functional notation)[expr.type.conv]1A simple-type-specifier (7.1.6.2) or typename-specifier (14.6) followed by a parenthesized expression-listconstructs a value of the specified type given the expression list.
If the expression list is a single expression,the type conversion expression is equivalent (in definedness, and if defined in meaning) to the correspondingcast expression (5.4). If the type specified is a class type, the class type shall be complete. If the expressionlist specifies more than a single value, the type shall be a class with a suitably declared constructor (8.5, 12.1),and the expression T(x1, x2, ...) is equivalent in effect to the declaration T t(x1, x2, ...); for someinvented temporary variable t, with the result being the value of t as a prvalue.2The expression T(), where T is a simple-type-specifier or typename-specifier for a non-array complete object type or the (possibly cv-qualified) void type, creates a prvalue of the specified type,which is valueinitialized (8.5; no initialization is done for the void() case).
[ Note: if T is a non-class type that iscv-qualified, the cv-qualifiers are ignored when determining the type of the resulting prvalue (3.10). — endnote ]3Similarly, a simple-type-specifier or typename-specifier followed by a braced-init-list creates a temporaryobject of the specified type direct-list-initialized (8.5.4) with the specified braced-init-list, and its value isthat temporary object as a prvalue.5.2.4Pseudo destructor call[expr.pseudo]1The use of a pseudo-destructor-name after a dot . or arrow -> operator represents the destructor for thenon-class type denoted by type-name or decltype-specifier. The result shall only be used as the operand forthe function call operator (), and the result of such a call has type void.
The only effect is the evaluationof the postfix-expression before the dot or arrow.2The left-hand side of the dot operator shall be of scalar type. The left-hand side of the arrow operator shallbe of pointer to scalar type. This scalar type is the object type. The cv-unqualified versions of the objecttype and of the type designated by the pseudo-destructor-name shall be the same type.
Furthermore, thetwo type-names in a pseudo-destructor-name of the formnested-name-specifieropt type-name :: ~ type-nameshall designate the same scalar type.5.2.51Class member access[expr.ref ]A postfix expression followed by a dot . or an arrow ->, optionally followed by the keyword template (14.2),and then followed by an id-expression, is a postfix expression. The postfix expression before the dot or arrow§ 5.2.5100© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)is evaluated;64 the result of that evaluation, together with the id-expression, determines the result of theentire postfix expression.2For the first option (dot) the first expression shall have complete class type.
For the second option (arrow)the first expression shall have pointer to complete class type. The expression E1->E2 is converted to theequivalent form (*(E1)).E2; the remainder of 5.2.5 will address only the first option (dot).65 In either case,the id-expression shall name a member of the class or of one of its base classes. [ Note: because the nameof a class is inserted in its class scope (Clause 9), the name of a class is also considered a nested memberof that class.
— end note ] [ Note: 3.4.5 describes how names are looked up after the . and -> operators.— end note ]3Abbreviating postfix-expression.id-expression as E1.E2, E1 is called the object expression. The type andvalue category of E1.E2 are determined as follows. In the remainder of 5.2.5, cq represents either constor the absence of const and vq represents either volatile or the absence of volatile. cv represents anarbitrary set of cv-qualifiers, as defined in 3.9.3.4If E2 is declared to have type “reference to T,” then E1.E2 is an lvalue; the type of E1.E2 is T.