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

             Bug #: 51811
           Summary: [C++0x] Incorrect incrementation/decrementation of
                    atomic pointers
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: libstdc++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: t.schu...@web.de


Incrementation (decrementation) of atomic pointers does not work correctly. On
an x86-64 machine the piece of code given below produces the following output
(or something similar):

0x7fffbe6d082c
0x7fffbe6d082d
0x7fffbe6d0830
0x7fffbe6d082d

There are two problems here: Firstly, the pointer is incremented by 1 and not
by sizeof(int). Secondly, the last two lines of the output should be the same.
Note that the second problem seems to be fixed in gcc-4.7-20120107, while the
first one still occurs. Thanks for your help!

----------------------------

#include <iostream>
#include <atomic>

using namespace std;

int main(int argc, char* argv[]) {
  int value = 42;
  atomic<int*> my_pointer;
  my_pointer = &value;
  cout << my_pointer++ << endl;
  cout << my_pointer << endl;
  my_pointer = &value;
  cout << ++my_pointer << endl;
  cout << my_pointer << endl;
}

Reply via email to