It gives an unexpected result while doing xor operation on a templated class. For sample, here is my simple code: ------------------------------------------------------ #include <iostream> using namespace std; template <class T> inline void XOR-Swap(T &a, T &b) { if (a != b) a ^= b ^= a ^= b; }; int main() { int a = 10; int b = -3; XOR-Swap(a, b); cout << a << endl; cout << b << endl; return 0; } ----------------------------------------------------- Results: 1. with "-O0": Incorrect ------------------- 0 10 ------------------- 2. with "-O1": Correct ------------------- -3 10 ------------------- Any comment?
(In reply to comment #0) > Any comment? this is an example of undefined behaviour. http://blogs.msdn.com/rick_schaut/archive/2004/03/06/85357.aspx
http://gcc.gnu.org/bugs.html#nonbugs_c *** This bug has been marked as a duplicate of 11751 ***