From Jason Turner

[expr.call]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. 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 pointer to function
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 pointer to function type. Calling a function through an
12
- expression whose function type has a language linkage that is different
13
- from the language linkage of the function type of the called function’s
14
- definition is undefined ([[dcl.link]]). For a call to a non-static
15
- member function, the postfix expression shall be an implicit (
16
- [[class.mfct.non-static]],  [[class.static]]) or explicit class member
17
- access ([[expr.ref]]) whose *id-expression* is a function member name,
18
- or a pointer-to-member expression ([[expr.mptr.oper]]) selecting a
19
- function member; the call is as a member of the class object referred to
20
- by the object expression. In the case of an implicit class member
21
- access, the implied object is the one pointed to by `this`. a member
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
- If a function or member function name is used, and name lookup (
37
- [[basic.lookup]]) does not find a declaration of that name, the program
38
- is ill-formed. No function is implicitly declared by such a call.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 `void`.
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. Such initializations are indeterminately
50
- sequenced with respect to each other ([[intro.execution]]) If the
51
- function is a non-static member function, the `this` parameter of the
52
- function ([[class.this]]) shall be initialized with a pointer to the
53
- object of the call, converted as if by an explicit type conversion (
54
- [[expr.cast]]). There is no access or ambiguity checking on this
55
- conversion; the access checking and disambiguation are done as part of
56
- the (possibly implicit) class member access operator. See 
57
- [[class.member.lookup]],  [[class.access.base]], and  [[expr.ref]]. When
58
- a function is called, the parameters that have object type shall have
59
- completely-defined object type. this still allows a parameter to be a
60
- pointer or reference to an incomplete class type. However, it prevents a
61
- passed-by-value parameter to have an incomplete class type. During the
62
- initialization of a parameter, an implementation may avoid the
63
- construction of extra temporaries by combining the conversions on the
64
- associated argument and/or the construction of temporaries with the
65
- initialization of the parameter (see  [[class.temporary]]). The lifetime
66
- of a parameter ends when the function in which it is defined returns.
67
- The initialization and destruction of each parameter occurs within the
68
- context of the calling function. the access of the constructor,
69
- conversion functions or destructor is checked at the point of call in
70
- the calling function. If a constructor or destructor for a function
71
- parameter throws an exception, the search for a handler starts in the
72
- scope of the calling function; in particular, if the function called has
73
- a *function-try-block* (Clause  [[except]]) with a handler that could
74
- handle the exception, this handler is not considered. The value of a
75
- function call is the value returned by the called function except in a
76
- virtual function call if the return type of the final overrider is
77
- different from the return type of the statically chosen function, the
78
- value returned from the final overrider is converted to the return type
79
- of the statically chosen function.
80
-
81
- a function can change the values of its non-const parameters, but these
82
- changes cannot affect the values of the arguments except where a
83
- parameter is of a reference type ([[dcl.ref]]); if the reference is to
84
- a const-qualified type, `const_cast` is required to be used to cast away
85
- the constness in order to modify the argument’s value. Where a parameter
86
- is of `const` reference type a temporary object is introduced if
87
- needed ([[dcl.type]],  [[lex.literal]],  [[lex.string]], 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  [[dcl.array]],  [[class.temporary]]). In addition, it is possible to
89
- modify the values of nonconstant objects through pointer parameters.
 
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
- this implies that, except where the ellipsis (`...`) or a function
96
- parameter pack is used, a parameter is available for each argument.
 
 
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]]). This paragraph
101
- does not apply to arguments passed to a function parameter pack.
102
- Function parameter packs are expanded during template instantiation (
103
- [[temp.variadic]]), thus each such argument has a corresponding
104
- parameter when a function template specialization is actually called.
 
 
 
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 (possibly cv-qualified) type `std::nullptr_t` is converted to type
109
- `void*` ([[conv.ptr]]). After these conversions, if the argument does
110
- not have arithmetic, enumeration, pointer, pointer to member, or class
111
- type, the program is ill-formed. Passing a potentially-evaluated
112
- argument of class type (Clause  [[class]]) having a non-trivial copy
113
- constructor, a non-trivial move constructor, or a non-trivial
114
- destructor, with no corresponding parameter, is conditionally-supported
115
- with *implementation-defined* semantics. If the argument has integral or
116
  enumeration type that is subject to the integral promotions (
117
- [[conv.prom]]), or a floating point type that is subject to the floating
118
- point promotion ([[conv.fpprom]]), the value of the argument is
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