The behavior of this program is not undefined but it is unspecified, if we look at the draft C++ standard section 1.9
Program execution paragraph 15 says(emphasis mine):
Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced. [ Note: In an expression that is evaluated more than once during the execution of a program, unsequenced and indeterminately sequenced evaluations of its subexpressions need not be performed consistently in different evaluations. —end note ] The value computations of the operands of an operator are sequenced before the value computation of the result of the operator. If a side effect on a scalar
object is unsequenced relative to either another side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined.
and if we check section 5.7
Additive operators which covers +
and -
that section does not specify an ordering so it is unsequenced.
In this case func
has a side effect since it is outputting to stdout
and so the order of the output is going to depend on the implementation and it even could change for subsequent evaluations.
Note that the ;
ends an expression statement and section 6.2
Expression statement says:
[...]All side effects from an expression statement are completed before the next statement is executed.[...]
so although the order of the function calls is unspecified, the side effects of each statement are completed before the next.