Given a function call func(E1, E2, E3)
where E1 etc are arbitrary expressions, is it true that each expression is indeterminately sequenced with respect to each other expression, or are all the expressions unsequenced (i.e. the evaluations can overlap)?
I've looked at the cppreference page on this and it, in rule 15, uses the sentence
In a function call, value computations and side effects of the initialization of every parameter are indeterminately sequenced with respect to value computations and side effects of any other parameter.
which I don't think is quite the same as what I'm asking as the initialisation of the parameter is just the last step in evaluation of the parameter's expression.
But rule 21 which is talking about something else seems to imply that each sub-expression in a function call is indeterminately sequenced
Every expression in a comma-separated list of expressions in a parenthesized initializer is evaluated as if for a function call (indeterminately-sequenced)
So I'm a bit confused and any guidance is appreciated.
"Order of evaluation" refers to when different subexpressions within the same expression are evaulated relative to each other. you have the usual precedence rules between multiplication and addition.
The order of evaluation of function arguments is unspecified. Consequently, parameters of a function shall not be used in a default argument, even if they are not evaluated. The same verbiage is used by C++14 standard as well, and is found under the same section.
evaluation order and sequence points Order of evaluation of the operands of any C operator, including the order of evaluation of function arguments in a function-call expression, and the order of evaluation of the subexpressions within any expression is unspecified (except where noted below).
User-defined conversion. Order of evaluation of any part of any expression, including order of evaluation of function arguments is unspecified (with some exceptions listed below). The compiler can evaluate operands and other subexpressions in any order, and may choose another order when the same expression is evaluated again.
Order of evaluation. Order of evaluation of the operands of any C operator, including the order of evaluation of function arguments in a function-call expression, and the order of evaluation of the subexpressions within any expression is unspecified (except where noted below). The compiler will evaluate them in any order,...
14) In a function-call expression, the expression that names the function is sequenced before every argument expression and every default argument.
Only the sequential-evaluation (, ), logical-AND ( && ), logical-OR ( || ), conditional-expression (? : ), and function-call operators constitute sequence points, and therefore guarantee a particular order of evaluation for their operands. The function-call operator is the set of parentheses following the function identifier.
C++17 states in
8.2.2 Function call [expr.call]
4 ... The initialization and destruction of each parameter occurs within the context of the calling function.
5 ... Note: All side effects of argument evaluations are sequenced before the function is entered
5 ... The initialization of a parameter, including every associated value computation and side effect, is indeterminately sequenced with respect to that of any other parameter.
I hope this (my bolding) is clear enough.
(ref: n4659, final C++17 draft)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With