Did c++17 actually change sequencing of function argument evaluations?

151 views
Skip to first unread message

Sergey Zubkov

unread,
Sep 2, 2016, 10:52:50 AM9/2/16
to ISO C++ Standard - Discussion
p0145 was initially trying to sequence function arguments left to right, that failed, but the backup plan was voted in. As far as I understand the backup plan, it introduces sequencing between arguments, but indeterminate rather than left-to-right.

I believe that was the intent because 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0145r3.pdf says "alternate evaluation rule for function calls: ... evaluations of the arguments are indeterminately sequenced, but with no interleaving"
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0400r0.html  says "wording for 5.2.2 [expr.call] paragraph 4 describing the indeterminate sequencing of function argument evaluation"

It doesn't seem that the changes to the wording actually achieved that effect, or at least are not clear that they did, as exemplified in this stackoverflow discussion: http://stackoverflow.com/a/39238441 about the permissible order of calls to a(), b(), x(), y() in f(a(x()), b(y()));

5.2.2 used to say 
> When a function is called, each parameter shall be initialized with its corresponding argument. [ Note: Such initializations are indeterminately sequenced with respect to each other —end note ]
and
> [ Note: The evaluations of ... the arguments are all unsequenced relative to one another.

now both notes (one calling argument evaluation unsequenced and the other calling parameter initialization indeterminately-sequenced) are removed and it says instead

> The initialization of a parameter, including every associated value computation and side effect, is indeterminately sequenced with respect to that of any other parameter.

but this is only talking about parameter initializations, which were already sequenced before the change (per removed note). Argument evaluation is not mentioned any more (and anything not mentioned is unsequenced per [intro.execution]/15).  I thought  argument evaluation was part of parameter initialization, but the removed note makes me doubt that's the intended interpretation.

So are argument evaluations still unsequenced (permitting x(), y(), b(), a() in f(a(x()), b(y()))or are they indeterminately-sequenced, permitting only x(),a(),y(),b() and y(),b(),x(),a(), and how does the wording reflect that? 

Richard Smith

unread,
Sep 2, 2016, 1:54:49 PM9/2/16
to std-dis...@isocpp.org
On Fri, Sep 2, 2016 at 7:52 AM, Sergey Zubkov <cubb...@gmail.com> wrote:
p0145 was initially trying to sequence function arguments left to right, that failed, but the backup plan was voted in. As far as I understand the backup plan, it introduces sequencing between arguments, but indeterminate rather than left-to-right.

I believe that was the intent because 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0145r3.pdf says "alternate evaluation rule for function calls: ... evaluations of the arguments are indeterminately sequenced, but with no interleaving"
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0400r0.html  says "wording for 5.2.2 [expr.call] paragraph 4 describing the indeterminate sequencing of function argument evaluation"

It doesn't seem that the changes to the wording actually achieved that effect, or at least are not clear that they did, as exemplified in this stackoverflow discussion: http://stackoverflow.com/a/39238441 about the permissible order of calls to a(), b(), x(), y() in f(a(x()), b(y()));

5.2.2 used to say 
> When a function is called, each parameter shall be initialized with its corresponding argument. [ Note: Such initializations are indeterminately sequenced with respect to each other —end note ]
and
> [ Note: The evaluations of ... the arguments are all unsequenced relative to one another.

now both notes (one calling argument evaluation unsequenced and the other calling parameter initialization indeterminately-sequenced) are removed and it says instead

> The initialization of a parameter, including every associated value computation and side effect, is indeterminately sequenced with respect to that of any other parameter.

but this is only talking about parameter initializations, which were already sequenced before the change (per removed note). Argument evaluation is not mentioned any more (and anything not mentioned is unsequenced per [intro.execution]/15).  I thought  argument evaluation was part of parameter initialization, but the removed note makes me doubt that's the intended interpretation.

The note on parameter initialization order was previously simply wrong. The normative wording provided no sequencing for those initializations.
 
So are argument evaluations still unsequenced (permitting x(), y(), b(), a() in f(a(x()), b(y()))or are they indeterminately-sequenced, permitting only x(),a(),y(),b() and y(),b(),x(),a(), and how does the wording reflect that?

The initialization of each parameter, including all of the implied evaluations from evaluating the initializer, is indeterminately sequenced with the initialization of any other parameter in the same call (again including all of the implied evaluations from evaluating the initializer).
Reply all
Reply to author
Forward
0 new messages