Skip to content

Commit 7d83acd

Browse files
authored
Rework some wording around out and inout parameters (#312)
This somewhat future proofs some aspects of the language here by saying that [in]out parameter initialization is copy-initialization, but the writeback assignment is _assignment_. That allows for clarity around overloaded operators so that the argument life becomes something like this: ``` auto &ArgTmp = (Arg); // Evaluate the argument expr saving it. T Param = ArgTmp; // Copy-initialize Param with Arg's result. call(Param); // Call the function. ArgTmp = Param; // Assign back the Param result with =. ```
1 parent 8b2b3df commit 7d83acd

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

specs/language/expressions.tex

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@
191191

192192
\p Parameters are either \textit{input parameters}, \textit{output parameters},
193193
or \textit{input/output parameters} as denoted in the called function's
194-
declaration (\ref{Decl.Function}).
194+
declaration (\ref{Decl.Function}). For all types of parameters the argument
195+
expressions are evaluated before the function call occurs.
195196

196197
\p \textit{Input parameters} are passed by-value into a function. If an argument
197198
to an \textit{input parameter} is of constant-sized array type, the array is
@@ -207,9 +208,11 @@
207208
undefined behavior to not explicitly initialize an \textit{output parameter}
208209
before returning from the function in which it is defined. The cxvalue created
209210
from an argument to an \textit{input/output parameter} is initialized through
210-
copy-initialization from the lvalue argument expression. In both cases, the
211-
cxvalue shall have the type of the parameter and the argument can be converted
212-
to that type through implicit or explicit conversion.
211+
copy-initialization from the lvalue argument expression. Overload resolution
212+
shall occur on argument initialization as if the expression \texttt{T Param =
213+
Arg} were evaluated. In both cases, the cxvalue shall have the type of the
214+
parameter and the argument can be converted to that type through implicit or
215+
explicit conversion.
213216

214217
\p If an argument to an \textit{output} or \textit{input/output parameter} is a
215218
constant sized array, the array is copied to a temporary cxvalue following the
@@ -222,11 +225,14 @@
222225
\texttt{T[N]}.
223226

224227
\p On expiration of the cxvalue, the value is assigned back to the argument
225-
lvalue expression following an inverted conversion if applicable. The argument
226-
expression must be of a type or able to convert to a type that has defined
227-
copy-initialization to and from the parameter type. The lifetime of the cxvalue
228-
begins at argument expression evaluation, and ends after the function returns. A
229-
cxvalue argument is passed by-address to the caller.
228+
lvalue expression using a resolved assignment expression as if the expression
229+
\texttt{Arg = Param} were written\footnote{The argument expression is not
230+
re-evaluated after the call, so any side effects of the call occur only before
231+
the call.}. The argument expression must be of a type or able to convert to a
232+
type that has defined copy-initialization to and assignment from the parameter
233+
type. The lifetime of the cxvalue begins at argument expression evaluation, and
234+
ends after the function returns. A cxvalue argument is passed by-address to the
235+
caller.
230236

231237
\p If the lvalue passed to an \textit{output} or \textit{input/output parameter}
232238
does not alias any other parameter passed to that function, an implementation

0 commit comments

Comments
 (0)