Q:

Why does this swap using simple addition and subtraction won't overflow?

I was under the impression that only swap using X-OR would work when we are providing inputs that are close to max limit of integer. Surprisingly this simple swap using addition and subtraction is working with those inputs too.
#include <iostream>

void simple_swap(int &x, int &y) {
    x += y;
    y = x - y;
    x -= y;
}

int main() {
    int a = 10; int b = 15;

    /* Testing integer overflow, sum has 1 bit outside of 4-bytes integer limit */
    a = 0xFFFFFFFF;     // a is 2^32-1 = 4294967295
    b = 0xFFFFFFFE;     // b is 2^32-2 = 4294967294

    std::cout << "Before swap " << "a = " << (unsigned int)a << ", b=" << (unsigned int)b << std::endl;
    simple_swap(a, b);
    std::cout << "After swap " << "a = " << (unsigned int)a << ", b=" << (unsigned int)b << std::endl;

    return 0;
}

I'm using Visual Studio 2013. If you are using a different compiler and the code does not work as showed in output let me know in comments.
I'm interested in knowing the reason behind this. Is compiler replacing the code with something else?

A:

Swap using addition
Even if it seems to work it's a bad idea.
void simple_swap(int &x, int &y) {
    x += y;
    y = x - y;
    x -= y;
}

if both x and y are really big or really small you'll get integer overflow/underflow which is undefined behavior. That means even if it seems to work for you there aren't any guarantees that it will work for anyone else or even when you compile it the next time. It can just break from one moment to the other.
Swap using xor
Also just for the record, using xor for swapping is broken too, for a whole different reason though.
void simple_swap(int &x, int &y) {
    x ^= y;
    y ^= x;
    x ^= y;
}

works most of the time but if you were to try and swap a variable with itself it would break:
simple_swap(a, a);

void simple_swap(int &x, int &y) { // both x and y refer to the same variable (a).
    x ^= y; // both variables will be 0 after this statement.
    y ^= x;
    x ^= y;
}

Now swapping a variable with itself might seem dumb and unlikely but you don't always know. It could be two pointers that just happen to point to the same variable and suddenly you got a weird bug. To make sure that it'd always work you'd have to make it overly complicated and test that both parameters aren't actually the same.
void simple_swap(int &x, int &y) {
    if ( x != y) {
        x ^= y;
        y ^= x;
        x ^= y;
    }
}

harder to read than such a simple function should be and not as simple as one thinks at first.
The correct way
Just use the simple and easy correct way, don't try to be clever:
void simple_swap(int &x, int &y) {
    int temp = x;
    x = y;
    y = temp;
}

Swapping is simple, every compiler will be able to optimize it to the best version.

