This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/32067] New: template<class T> XOR-Swap(T &a, T &b); error with -O0 option
- From: "nanericwang at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 May 2007 11:16:01 -0000
- Subject: [Bug c++/32067] New: template<class T> XOR-Swap(T &a, T &b); error with -O0 option
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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?
--
Summary: template<class T> XOR-Swap(T &a, T &b); error with -O0
option
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nanericwang at hotmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32067