The answer to this question changed in C++17.
Evaluation of overloaded operators are now sequenced in the same way as for built-in operators (C++17 [over.match.oper]/2).
Furthermore, the <<
, >>
and subscripting operators now have the left operand sequenced before the right, and the postfix-expression of a function call is sequenced before evaluation of the arguments.
(The other binary operators retain their previous sequencing, e.g. +
is still unsequenced).
So the code in the question must now output Value of test is : 0 Return value of function is : 1 Value of test : 1
. But the advice “Don’t do this” is still reasonable, given that it will take some time for everybody to update to C++17.