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; }
Mine
Author: bkoz Date: Fri Feb 3 19:49:11 2012 New Revision: 183875 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183875 Log: 2012-02-03 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/51811 * include/bits/atomic_base.h (atomic<_Tp*>): Fix offsets. * testsuite/29_atomics/atomic/operators/51811.cc: New. * testsuite/29_atomics/atomic/operators/pointer_partial_void.cc: New. Added: trunk/libstdc++-v3/testsuite/29_atomics/atomic/operators/51811.cc trunk/libstdc++-v3/testsuite/29_atomics/atomic/operators/pointer_partial_void.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/bits/atomic_base.h
Fixed for 4.7
Author: jingyu Date: Fri Jul 20 17:27:57 2012 New Revision: 189724 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189724 Log: 2012-07-19 Jing Yu <jingyu@google.com> Backport r183875 to fix wrong atomic<_Tp*> add_fetch. PR libstdc++/51811, Google ref b/6702865 * include/bits/atomic_0.h (atomic<_Tp*>): Fix offsets. * include/bits/atomic_2.h: Likewise. * testsuite/29_atomics/atomic/operators/51811.cc: New. * testsuite/29_atomics/atomic/operators/pointer_partial_void.cc: New. Added: branches/google/gcc-4_6/libstdc++-v3/testsuite/29_atomics/atomic/operators/51811.cc branches/google/gcc-4_6/libstdc++-v3/testsuite/29_atomics/atomic/operators/pointer_partial_void.cc Modified: branches/google/gcc-4_6/libstdc++-v3/ChangeLog.google-4_6 branches/google/gcc-4_6/libstdc++-v3/include/bits/atomic_0.h branches/google/gcc-4_6/libstdc++-v3/include/bits/atomic_2.h