Skip to content

Commit f7d2c6d

Browse files
committed
Merge 2016-06 CWG Motion 9
2 parents 25ccd9f + cdcabf2 commit f7d2c6d

File tree

4 files changed

+56
-32
lines changed

4 files changed

+56
-32
lines changed

source/declarators.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,11 @@
27982798
An \grammarterm{initializer-clause} followed by an ellipsis is a
27992799
pack expansion~(\ref{temp.variadic}).
28002800

2801+
\pnum
2802+
If the initializer is a parenthesized \grammarterm{expression-list},
2803+
the expressions are evaluated in the order
2804+
specified for function calls~(\ref{expr.call}).
2805+
28012806
\rSec2[dcl.init.aggr]{Aggregates}%
28022807
\indextext{aggregate}%
28032808
\indextext{initialization!aggregate}%

source/expressions.tex

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
expressions of class type~(Clause \ref{class}) or enumeration
3333
type~(\ref{dcl.enum}). Uses of overloaded operators are transformed into
3434
function calls as described in~\ref{over.oper}. Overloaded operators
35-
obey the rules for syntax specified in Clause~\ref{expr}, but the
36-
requirements of operand type, value category, and evaluation order are replaced
35+
obey the rules for syntax and evaluation order specified in Clause~\ref{expr},
36+
but the requirements of operand type and value category are replaced
3737
by the rules for function call. Relations between operators, such as
3838
\tcode{++a} meaning \tcode{a+=1}, are not guaranteed for overloaded
3939
operators~(\ref{over.oper}).
@@ -1461,6 +1461,7 @@
14611461
\tcode{+} and~\ref{dcl.array} for details of arrays.
14621462
\end{note}, except that in the case of an array operand, the result is an lvalue
14631463
if that operand is an lvalue and an xvalue otherwise.
1464+
The expression \tcode{E1} is sequenced before the expression \tcode{E2}.
14641465

14651466
\pnum
14661467
A \grammarterm{braced-init-list} shall not be used with the built-in subscript operator.
@@ -1538,8 +1539,6 @@
15381539
When a function is called, each parameter~(\ref{dcl.fct}) shall be
15391540
initialized~(\ref{dcl.init},~\ref{class.copy},~\ref{class.ctor}) with
15401541
its corresponding argument.
1541-
\begin{note} Such initializations are indeterminately sequenced
1542-
with respect to each other~(\ref{intro.execution}) \end{note}
15431542
If the function is a non-static member
15441543
function, the \tcode{this} parameter of the function~(\ref{class.this})
15451544
shall be initialized with a pointer to the object of the call, converted
@@ -1573,6 +1572,33 @@
15731572
(Clause~\ref{except}) with a handler that could handle the exception,
15741573
this handler is not considered.
15751574
\end{example}
1575+
1576+
\pnum
1577+
\indextext{evaluation!order~of argument}%
1578+
\indextext{evaluation!unspecified order~of function~call}%
1579+
\indextext{evaluation!unspecified order~of argument}%
1580+
The \grammarterm{postfix-expression} is sequenced before
1581+
each \grammarterm{expression} in the \grammarterm{expression-list}
1582+
and any default argument.
1583+
The initialization of a parameter,
1584+
including every associated value computation and side effect,
1585+
is indeterminately sequenced with respect to that of any other parameter.
1586+
\begin{note}
1587+
All side effects of
1588+
argument evaluations are sequenced before the function is
1589+
entered (see~\ref{intro.execution}).
1590+
\end{note}
1591+
\begin{example}
1592+
\begin{codeblock}
1593+
void f() {
1594+
std::string s = "but I have heard it works even if you don't believe in it";
1595+
s.replace(0, 4, "").replace(s.find("even"), 4, "only").replace(s.find(" don't"), 6, "");
1596+
assert(s == "I have heard it works only if you believe in it"); // OK
1597+
}
1598+
\end{codeblock}
1599+
\end{example}
1600+
1601+
\pnum
15761602
The result of a function call is the
15771603
result of the operand of the evaluated \tcode{return} statement~(\ref{stmt.return})
15781604
in the called function (if any),
@@ -1642,18 +1668,6 @@
16421668
promoted type before the call. These promotions are referred to as
16431669
the \defnx{default argument promotions}{promotion!default argument promotion}.
16441670

1645-
\pnum
1646-
\indextext{evaluation!order~of argument}%
1647-
\indextext{evaluation!unspecified order~of function~call}%
1648-
\begin{note}
1649-
The evaluations of the postfix expression and of the arguments
1650-
are all unsequenced relative to one another.
1651-
\indextext{evaluation!unspecified order~of argument}%
1652-
All side effects of
1653-
argument evaluations are sequenced before the function is
1654-
entered (see~\ref{intro.execution}).
1655-
\end{note}
1656-
16571671
\pnum
16581672
\indextext{function~call!recursive}%
16591673
Recursive calls are permitted, except to the \tcode{main}
@@ -3393,16 +3407,12 @@
33933407
\pnum
33943408
\indextext{\idxcode{new}!unspecified order~of evaluation}%
33953409
\indextext{\idxcode{new}!unspecified constructor~and}%
3396-
The invocation of the allocation function is indeterminately sequenced with respect to
3410+
The invocation of the allocation function is sequenced before
33973411
the evaluations of expressions in the \grammarterm{new-initializer}. Initialization of
33983412
the allocated object is sequenced before the
33993413
\indextext{value computation}%
34003414
value computation of the
34013415
\grammarterm{new-expression}.
3402-
\indextext{constructor!unspecified argument~to}%
3403-
It is unspecified whether expressions in the \grammarterm{new-initializer} are
3404-
evaluated if the allocation function returns the null pointer or exits
3405-
using an exception.
34063416

34073417
\pnum
34083418
If the \grammarterm{new-expression} creates an object or an array of
@@ -3417,8 +3427,7 @@
34173427
If any part of the object initialization described above\footnote{This may
34183428
include evaluating a \grammarterm{new-initializer} and/or calling
34193429
a constructor.}
3420-
terminates by throwing an exception, storage has been obtained for the
3421-
object, and a suitable deallocation function
3430+
terminates by throwing an exception and a suitable deallocation function
34223431
can be found, the deallocation function is called to free the memory in
34233432
which the object was being constructed, after which the exception
34243433
continues to propagate in the context of the \grammarterm{new-expression}.
@@ -3871,6 +3880,7 @@
38713880
If the dynamic type of \tcode{E1} does not
38723881
contain the member to which
38733882
\tcode{E2} refers, the behavior is undefined.
3883+
Otherwise, the expression \tcode{E1} is sequenced before the expression \tcode{E2}.
38743884

38753885
\pnum
38763886
The restrictions on \cvqual{cv-}qualification, and the manner in which
@@ -4125,6 +4135,9 @@
41254135
has a signed type and a negative value, the resulting value is
41264136
\impldef{result of right shift of negative value}.
41274137

4138+
\pnum
4139+
The expression \tcode{E1} is sequenced before the expression \tcode{E2}.
4140+
41284141
\rSec1[expr.rel]{Relational operators}%
41294142
\indextext{expression!relational operators}%
41304143
\indextext{operator!relational}
@@ -4685,7 +4698,9 @@
46854698
\indextext{value computation}%
46864699
value computation of the right and left operands,
46874700
and before the
4688-
value computation of the assignment expression. With
4701+
value computation of the assignment expression.
4702+
The right operand is sequenced before the left operand.
4703+
With
46894704
respect to an indeterminately-sequenced function call, the operation of
46904705
a compound assignment is a single evaluation.
46914706
\begin{note}
@@ -4795,10 +4810,7 @@
47954810

47964811
A pair of expressions separated by a comma is evaluated left-to-right;
47974812
the left expression is
4798-
a discarded-value expression (Clause~\ref{expr}).\footnote{However, an
4799-
invocation of an overloaded comma operator is an ordinary function call; hence,
4800-
the evaluations of its argument expressions are unsequenced relative to one
4801-
another~(see \ref{intro.execution}).}
4813+
a discarded-value expression (Clause~\ref{expr}).
48024814
Every
48034815
\indextext{value computation}%
48044816
value computation and side effect

source/intro.tex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,14 @@
954954
\term{B} or \term{B} is sequenced before \term{A}, but it is unspecified which.
955955
\begin{note} Indeterminately sequenced evaluations cannot overlap, but either
956956
could be executed first. \end{note}
957+
An expression \placeholder{X}
958+
is said to be sequenced before
959+
an expression \placeholder{Y} if
960+
every value computation and every side effect
961+
associated with the expression \placeholder{X}
962+
is sequenced before
963+
every value computation and every side effect
964+
associated with the expression \placeholder{Y}.
957965

958966
\pnum
959967
Every
@@ -1012,10 +1020,7 @@
10121020
side effect associated with any argument
10131021
expression, or with the postfix expression designating the called
10141022
function, is sequenced before execution of every expression or statement
1015-
in the body of the called function. \begin{note}
1016-
Value computations and
1017-
side effects associated with different argument expressions are
1018-
unsequenced. \end{note}
1023+
in the body of the called function.
10191024
For each function invocation \term{F},
10201025
for every evaluation \term{A} that occurs within \term{F} and
10211026
every evaluation \term{B} that does not occur within \term{F} but

source/overloading.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,8 @@
962962
to the equivalent function-call notation as summarized in
963963
Table~\ref{tab:over.rel.op.func}
964964
(where \tcode{@} denotes one of the operators covered in the specified subclause).
965+
However, the operands are sequenced in the order prescribed
966+
for the built-in operator (Clause~\ref{expr}).
965967

966968
\begin{floattable}{Relationship between operator and function call notation}{tab:over.rel.op.func}
967969
{l|m|m|m}

0 commit comments

Comments
 (0)