This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/32067] New: template<class T> XOR-Swap(T &a, T &b); error with -O0 option


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]