It's undefined behaviour unless i
is a class type. From C++11 1.9/15:
Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced.
followed by a note to clarify that this does apply to function arguments:
[ Note: Value computations and side effects associated with different argument expressions are unsequenced. —end note ]
Your code modifies the same object twice without sequencing, so by the same paragraph:
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.
If i
were a class type, then ++
would call a function, and function calls are always sequenced with respect to each other. So any modifications of scalar objects would be indeterminately sequenced; there's no undefined behaviour, but the result is unspecified.