http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46914

           Summary: std::atomic<int*>::exchange(...) doesn't store correct
                    value.
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: frts...@hotmail.com


Run the following to compile the program below.
$ g++ -std=c++0x ./test.cpp -o test.tsk

//test.cpp
#include <iostream>
#include <stdatomic.h>

int main(int argc, char **argv)
{
    int *a = new int(10);
    std::cout << "a = " << a << " *a = " << *a << std::endl;

    std::atomic<int*> x(a);
    int *ptr = x;
    std::cout << "ptr = " << ptr << " *ptr " << *ptr << std::endl;

    int *b = new int(11);
    std::cout << "b = " << b << " *b = " << *b << std::endl;

    std::cout << "x.exchange(b) = " << x.exchange(b) << std::endl;
    ptr = x;
    std::cout << "ptr = " << ptr << " *ptr " << *ptr << std::endl;

    int *c = new int(12);
    std::cout << "c = " << c << " *c = " << *c << std::endl;

    std::cout << "x.exchange(c) = " << x.exchange(c) << std::endl;
    ptr = x;
    std::cout << "ptr = " << ptr << " *ptr " << *ptr << std::endl;

    return 0;
}

$ g++ --version
g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

It runs and gives the following result.

./test.tsk 
a = 0x9b9c008 *a = 10
ptr = 0x9b9c008 *ptr 10
b = 0x9b9c018 *b = 11
x.exchange(b) = 0x9b9c008
ptr = 0x1ec71b *ptr -388381823
c = 0x9b9c028 *c = 12
x.exchange(c) = 0x1ec71b
ptr = 0x1ec71b *ptr -388381823

After "x" is initialized with "a", it doesn't store the new value correctly in
its "exchange" member function.

Reply via email to