From Jason Turner

[expr.call]

Diff to HTML by rtfpessoa

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