>but the code seems to work ok.
Perhaps my wording was poor. If a and b refer to the same object, the result will be 0, regardless of what the original value was. Sure, you may argue that this is an unlikely event, but I've seen it fairly often, especially in sorting algorithms.
Oh you mean x ^= x?. I see your point about it not working when you want to swap the two values when they are both the same variable. swap function should never be called when the two variables are the same.