- tmp/tmppyp3xh1e/{from.md → to.md} +147 -110
tmp/tmppyp3xh1e/{from.md → to.md}
RENAMED
|
@@ -1,151 +1,188 @@
|
|
| 1 |
### Function call <a id="expr.call">[[expr.call]]</a>
|
| 2 |
|
| 3 |
A function call is a postfix expression followed by parentheses
|
| 4 |
containing a possibly empty, comma-separated list of
|
| 5 |
*initializer-clause*s which constitute the arguments to the function.
|
| 6 |
-
The postfix expression shall have function type or
|
| 7 |
type. For a call to a non-member function or to a static member
|
| 8 |
function, the postfix expression shall be either an lvalue that refers
|
| 9 |
to a function (in which case the function-to-pointer standard
|
| 10 |
conversion ([[conv.func]]) is suppressed on the postfix expression), or
|
| 11 |
-
it shall have
|
| 12 |
-
expression whose function type
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
[[class.
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
function call of the form `f()` is interpreted as `(*this).f()` (see
|
| 23 |
-
[[class.mfct.non-static]]). If a function or member function name is
|
| 24 |
-
used, the name can be overloaded (Clause [[over]]), in which case the
|
| 25 |
-
appropriate function shall be selected according to the rules in
|
| 26 |
-
[[over.match]]. If the selected function is non-virtual, or if the
|
| 27 |
-
*id-expression* in the class member access expression is a
|
| 28 |
-
*qualified-id*, that function is called. Otherwise, its final
|
| 29 |
-
overrider ([[class.virtual]]) in the dynamic type of the object
|
| 30 |
-
expression is called; such a call is referred to as a *virtual function
|
| 31 |
-
call*. the dynamic type is the type of the object referred to by the
|
| 32 |
-
current value of the object expression. [[class.cdtor]] describes the
|
| 33 |
-
behavior of virtual function calls when the object expression refers to
|
| 34 |
-
an object under construction or destruction.
|
| 35 |
|
| 36 |
-
|
| 37 |
-
[[
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
If the *postfix-expression* designates a destructor ([[class.dtor]]),
|
| 41 |
the type of the function call expression is `void`; otherwise, the type
|
| 42 |
of the function call expression is the return type of the statically
|
| 43 |
chosen function (i.e., ignoring the `virtual` keyword), even if the type
|
| 44 |
of the function actually called is different. This return type shall be
|
| 45 |
-
an object type, a reference type or cv
|
| 46 |
|
| 47 |
When a function is called, each parameter ([[dcl.fct]]) shall be
|
| 48 |
initialized ([[dcl.init]], [[class.copy]], [[class.ctor]]) with its
|
| 49 |
-
corresponding argument.
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
[
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
[[class.
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
parameter
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
[[dcl.array]], [[class.temporary]]). In addition, it is possible to
|
| 89 |
-
modify the values of
|
|
|
|
| 90 |
|
| 91 |
A function can be declared to accept fewer arguments (by declaring
|
| 92 |
default arguments ([[dcl.fct.default]])) or more arguments (by using
|
| 93 |
the ellipsis, `...`, or a function parameter pack ([[dcl.fct]])) than
|
| 94 |
the number of parameters in the function definition ([[dcl.fct.def]]).
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
|
| 98 |
When there is no parameter for a given argument, the argument is passed
|
| 99 |
in such a way that the receiving function can obtain the value of the
|
| 100 |
-
argument by invoking `va_arg` ([[support.runtime]]).
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
| 105 |
The lvalue-to-rvalue ([[conv.lval]]), array-to-pointer (
|
| 106 |
[[conv.array]]), and function-to-pointer ([[conv.func]]) standard
|
| 107 |
conversions are performed on the argument expression. An argument that
|
| 108 |
-
has
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
enumeration type that is subject to the integral promotions (
|
| 117 |
-
[[conv.prom]]), or a floating
|
| 118 |
-
point promotion ([[conv.fpprom]]), the value of the argument
|
| 119 |
-
converted to the promoted type before the call. These promotions are
|
| 120 |
referred to as the *default argument promotions*.
|
| 121 |
|
| 122 |
-
The evaluations of the postfix expression and of the arguments are all
|
| 123 |
-
unsequenced relative to one another. All side effects of argument
|
| 124 |
-
evaluations are sequenced before the function is entered (see
|
| 125 |
-
[[intro.execution]]).
|
| 126 |
-
|
| 127 |
Recursive calls are permitted, except to the `main` function (
|
| 128 |
[[basic.start.main]]).
|
| 129 |
|
| 130 |
A function call is an lvalue if the result type is an lvalue reference
|
| 131 |
type or an rvalue reference to function type, an xvalue if the result
|
| 132 |
type is an rvalue reference to object type, and a prvalue otherwise.
|
| 133 |
|
| 134 |
-
If a function call is a prvalue of object type:
|
| 135 |
-
|
| 136 |
-
- if the function call is either
|
| 137 |
-
- the operand of a *decltype-specifier* or
|
| 138 |
-
- the right operand of a comma operator that is the operand of a
|
| 139 |
-
*decltype-specifier*,
|
| 140 |
-
|
| 141 |
-
a temporary object is not introduced for the prvalue. The type of the
|
| 142 |
-
prvalue may be incomplete. as a result, storage is not allocated for
|
| 143 |
-
the prvalue and it is not destroyed; thus, a class type is not
|
| 144 |
-
instantiated as a result of being the type of a function call in this
|
| 145 |
-
context. This is true regardless of whether the expression uses
|
| 146 |
-
function call notation or operator notation ([[over.match.oper]]).
|
| 147 |
-
unlike the rule for a *decltype-specifier* that considers whether an
|
| 148 |
-
*id-expression* is parenthesized ([[dcl.type.simple]]), parentheses
|
| 149 |
-
have no special meaning in this context.
|
| 150 |
-
- otherwise, the type of the prvalue shall be complete.
|
| 151 |
-
|
|
|
|
| 1 |
### Function call <a id="expr.call">[[expr.call]]</a>
|
| 2 |
|
| 3 |
A function call is a postfix expression followed by parentheses
|
| 4 |
containing a possibly empty, comma-separated list of
|
| 5 |
*initializer-clause*s which constitute the arguments to the function.
|
| 6 |
+
The postfix expression shall have function type or function pointer
|
| 7 |
type. For a call to a non-member function or to a static member
|
| 8 |
function, the postfix expression shall be either an lvalue that refers
|
| 9 |
to a function (in which case the function-to-pointer standard
|
| 10 |
conversion ([[conv.func]]) is suppressed on the postfix expression), or
|
| 11 |
+
it shall have function pointer type. Calling a function through an
|
| 12 |
+
expression whose function type is different from the function type of
|
| 13 |
+
the called function’s definition results in undefined behavior (
|
| 14 |
+
[[dcl.link]]). For a call to a non-static member function, the postfix
|
| 15 |
+
expression shall be an implicit ([[class.mfct.non-static]],
|
| 16 |
+
[[class.static]]) or explicit class member access ([[expr.ref]]) whose
|
| 17 |
+
*id-expression* is a function member name, or a pointer-to-member
|
| 18 |
+
expression ([[expr.mptr.oper]]) selecting a function member; the call
|
| 19 |
+
is as a member of the class object referred to by the object expression.
|
| 20 |
+
In the case of an implicit class member access, the implied object is
|
| 21 |
+
the one pointed to by `this`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
[*Note 1*: A member function call of the form `f()` is interpreted as
|
| 24 |
+
`(*this).f()` (see [[class.mfct.non-static]]). — *end note*]
|
| 25 |
+
|
| 26 |
+
If a function or member function name is used, the name can be
|
| 27 |
+
overloaded (Clause [[over]]), in which case the appropriate function
|
| 28 |
+
shall be selected according to the rules in [[over.match]]. If the
|
| 29 |
+
selected function is non-virtual, or if the *id-expression* in the class
|
| 30 |
+
member access expression is a *qualified-id*, that function is called.
|
| 31 |
+
Otherwise, its final overrider ([[class.virtual]]) in the dynamic type
|
| 32 |
+
of the object expression is called; such a call is referred to as a
|
| 33 |
+
*virtual function call*.
|
| 34 |
+
|
| 35 |
+
[*Note 2*: The dynamic type is the type of the object referred to by
|
| 36 |
+
the current value of the object expression. [[class.cdtor]] describes
|
| 37 |
+
the behavior of virtual function calls when the object expression refers
|
| 38 |
+
to an object under construction or destruction. — *end note*]
|
| 39 |
+
|
| 40 |
+
[*Note 3*: If a function or member function name is used, and name
|
| 41 |
+
lookup ([[basic.lookup]]) does not find a declaration of that name, the
|
| 42 |
+
program is ill-formed. No function is implicitly declared by such a
|
| 43 |
+
call. — *end note*]
|
| 44 |
|
| 45 |
If the *postfix-expression* designates a destructor ([[class.dtor]]),
|
| 46 |
the type of the function call expression is `void`; otherwise, the type
|
| 47 |
of the function call expression is the return type of the statically
|
| 48 |
chosen function (i.e., ignoring the `virtual` keyword), even if the type
|
| 49 |
of the function actually called is different. This return type shall be
|
| 50 |
+
an object type, a reference type or cv `void`.
|
| 51 |
|
| 52 |
When a function is called, each parameter ([[dcl.fct]]) shall be
|
| 53 |
initialized ([[dcl.init]], [[class.copy]], [[class.ctor]]) with its
|
| 54 |
+
corresponding argument. If the function is a non-static member function,
|
| 55 |
+
the `this` parameter of the function ([[class.this]]) shall be
|
| 56 |
+
initialized with a pointer to the object of the call, converted as if by
|
| 57 |
+
an explicit type conversion ([[expr.cast]]).
|
| 58 |
+
|
| 59 |
+
[*Note 4*: There is no access or ambiguity checking on this conversion;
|
| 60 |
+
the access checking and disambiguation are done as part of the (possibly
|
| 61 |
+
implicit) class member access operator. See [[class.member.lookup]],
|
| 62 |
+
[[class.access.base]], and [[expr.ref]]. — *end note*]
|
| 63 |
+
|
| 64 |
+
When a function is called, the parameters that have object type shall
|
| 65 |
+
have completely-defined object type.
|
| 66 |
+
|
| 67 |
+
[*Note 5*: this still allows a parameter to be a pointer or reference
|
| 68 |
+
to an incomplete class type. However, it prevents a passed-by-value
|
| 69 |
+
parameter to have an incomplete class type. — *end note*]
|
| 70 |
+
|
| 71 |
+
It is *implementation-defined* whether the lifetime of a parameter ends
|
| 72 |
+
when the function in which it is defined returns or at the end of the
|
| 73 |
+
enclosing full-expression. The initialization and destruction of each
|
| 74 |
+
parameter occurs within the context of the calling function.
|
| 75 |
+
|
| 76 |
+
[*Example 1*: The access of the constructor, conversion functions or
|
| 77 |
+
destructor is checked at the point of call in the calling function. If a
|
| 78 |
+
constructor or destructor for a function parameter throws an exception,
|
| 79 |
+
the search for a handler starts in the scope of the calling function; in
|
| 80 |
+
particular, if the function called has a *function-try-block* (Clause
|
| 81 |
+
[[except]]) with a handler that could handle the exception, this handler
|
| 82 |
+
is not considered. — *end example*]
|
| 83 |
+
|
| 84 |
+
The *postfix-expression* is sequenced before each *expression* in the
|
| 85 |
+
*expression-list* and any default argument. The initialization of a
|
| 86 |
+
parameter, including every associated value computation and side effect,
|
| 87 |
+
is indeterminately sequenced with respect to that of any other
|
| 88 |
+
parameter.
|
| 89 |
+
|
| 90 |
+
[*Note 6*: All side effects of argument evaluations are sequenced
|
| 91 |
+
before the function is entered (see
|
| 92 |
+
[[intro.execution]]). — *end note*]
|
| 93 |
+
|
| 94 |
+
[*Example 2*:
|
| 95 |
+
|
| 96 |
+
``` cpp
|
| 97 |
+
void f() {
|
| 98 |
+
std::string s = "but I have heard it works even if you don't believe in it";
|
| 99 |
+
s.replace(0, 4, "").replace(s.find("even"), 4, "only").replace(s.find(" don't"), 6, "");
|
| 100 |
+
assert(s == "I have heard it works only if you believe in it"); // OK
|
| 101 |
+
}
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
— *end example*]
|
| 105 |
+
|
| 106 |
+
[*Note 7*: If an operator function is invoked using operator notation,
|
| 107 |
+
argument evaluation is sequenced as specified for the built-in operator;
|
| 108 |
+
see [[over.match.oper]]. — *end note*]
|
| 109 |
+
|
| 110 |
+
[*Example 3*:
|
| 111 |
+
|
| 112 |
+
``` cpp
|
| 113 |
+
struct S {
|
| 114 |
+
S(int);
|
| 115 |
+
};
|
| 116 |
+
int operator<<(S, int);
|
| 117 |
+
int i, j;
|
| 118 |
+
int x = S(i=1) << (i=2);
|
| 119 |
+
int y = operator<<(S(j=1), j=2);
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
After performing the initializations, the value of `i` is 2 (see
|
| 123 |
+
[[expr.shift]]), but it is unspecified whether the value of `j` is 1 or
|
| 124 |
+
2.
|
| 125 |
+
|
| 126 |
+
— *end example*]
|
| 127 |
+
|
| 128 |
+
The result of a function call is the result of the operand of the
|
| 129 |
+
evaluated `return` statement ([[stmt.return]]) in the called function
|
| 130 |
+
(if any), except in a virtual function call if the return type of the
|
| 131 |
+
final overrider is different from the return type of the statically
|
| 132 |
+
chosen function, the value returned from the final overrider is
|
| 133 |
+
converted to the return type of the statically chosen function.
|
| 134 |
+
|
| 135 |
+
[*Note 8*: A function can change the values of its non-const
|
| 136 |
+
parameters, but these changes cannot affect the values of the arguments
|
| 137 |
+
except where a parameter is of a reference type ([[dcl.ref]]); if the
|
| 138 |
+
reference is to a const-qualified type, `const_cast` is required to be
|
| 139 |
+
used to cast away the constness in order to modify the argument’s value.
|
| 140 |
+
Where a parameter is of `const` reference type a temporary object is
|
| 141 |
+
introduced if needed ([[dcl.type]], [[lex.literal]], [[lex.string]],
|
| 142 |
[[dcl.array]], [[class.temporary]]). In addition, it is possible to
|
| 143 |
+
modify the values of non-constant objects through pointer
|
| 144 |
+
parameters. — *end note*]
|
| 145 |
|
| 146 |
A function can be declared to accept fewer arguments (by declaring
|
| 147 |
default arguments ([[dcl.fct.default]])) or more arguments (by using
|
| 148 |
the ellipsis, `...`, or a function parameter pack ([[dcl.fct]])) than
|
| 149 |
the number of parameters in the function definition ([[dcl.fct.def]]).
|
| 150 |
+
|
| 151 |
+
[*Note 9*: This implies that, except where the ellipsis (`...`) or a
|
| 152 |
+
function parameter pack is used, a parameter is available for each
|
| 153 |
+
argument. — *end note*]
|
| 154 |
|
| 155 |
When there is no parameter for a given argument, the argument is passed
|
| 156 |
in such a way that the receiving function can obtain the value of the
|
| 157 |
+
argument by invoking `va_arg` ([[support.runtime]]).
|
| 158 |
+
|
| 159 |
+
[*Note 10*: This paragraph does not apply to arguments passed to a
|
| 160 |
+
function parameter pack. Function parameter packs are expanded during
|
| 161 |
+
template instantiation ([[temp.variadic]]), thus each such argument has
|
| 162 |
+
a corresponding parameter when a function template specialization is
|
| 163 |
+
actually called. — *end note*]
|
| 164 |
+
|
| 165 |
The lvalue-to-rvalue ([[conv.lval]]), array-to-pointer (
|
| 166 |
[[conv.array]]), and function-to-pointer ([[conv.func]]) standard
|
| 167 |
conversions are performed on the argument expression. An argument that
|
| 168 |
+
has type cv `std::nullptr_t` is converted to type `void*` (
|
| 169 |
+
[[conv.ptr]]). After these conversions, if the argument does not have
|
| 170 |
+
arithmetic, enumeration, pointer, pointer to member, or class type, the
|
| 171 |
+
program is ill-formed. Passing a potentially-evaluated argument of class
|
| 172 |
+
type (Clause [[class]]) having a non-trivial copy constructor, a
|
| 173 |
+
non-trivial move constructor, or a non-trivial destructor, with no
|
| 174 |
+
corresponding parameter, is conditionally-supported with
|
| 175 |
+
*implementation-defined* semantics. If the argument has integral or
|
| 176 |
enumeration type that is subject to the integral promotions (
|
| 177 |
+
[[conv.prom]]), or a floating-point type that is subject to the
|
| 178 |
+
floating-point promotion ([[conv.fpprom]]), the value of the argument
|
| 179 |
+
is converted to the promoted type before the call. These promotions are
|
| 180 |
referred to as the *default argument promotions*.
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
Recursive calls are permitted, except to the `main` function (
|
| 183 |
[[basic.start.main]]).
|
| 184 |
|
| 185 |
A function call is an lvalue if the result type is an lvalue reference
|
| 186 |
type or an rvalue reference to function type, an xvalue if the result
|
| 187 |
type is an rvalue reference to object type, and a prvalue otherwise.
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|