Assignment operator (=) and all assignment operators group from right to left. [..]
The behavior of an expression of the form E1 op = E2 equivalent to E1 = E1 op E2 , except that E1 is evaluated only once.
So your code is equivalent
x = x ^ (y ^= (x ^= y)));
... with x is evaluated only once at x = x ... Unfortunately, for xor's, evaluating operands does not matter. I.e
Except where noted, evaluations of the operands of individual operators and subexpressions of individual expressions are not affected.
applies. But now we have a problem:
x = x ^ (y ^= (x ^= y))); // * ****** // | | // | Side effect // Value computation
The calculation of the value (which is implied in the singular estimate of x for the two left x ), and the side effect is independent of each other, so we induce UB:
If the side effect of a scalar object is independent of another side effect on the same scalar object or calculating a value using the value of the same scalar object, the behavior is undefined.
source share