]> gcc.gnu.org Git - gcc.git/commitdiff
re PR libstdc++/40654 ([C++0x] atomic.cc: 'd' is used uninitialized warning)
authorBenjamin Kosnik <bkoz@redhat.com>
Fri, 16 Oct 2009 07:47:33 +0000 (07:47 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Fri, 16 Oct 2009 07:47:33 +0000 (07:47 +0000)
2009-10-15  Benjamin Kosnik  <bkoz@redhat.com>

PR libstdc++/40654
PR libstdc++/40826
* src/atomic.cc (atomic_flag_test_and_set_explicit): Add
static_cast from base to derived.
(atomic_flag_clear_explicit): Same.
* include/bits/atomic_2.h (__atomic2::atomic_flag): Public derivation.
Remove value type constructor.
* include/bits/atomic_0.h (__atomic0::atomic_flag): Same.
* include/std/future (_Future_state): Use ATOMIC_FLAG_INIT to
initialized the atomic_flag member.

From-SVN: r152895

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/atomic_0.h
libstdc++-v3/include/bits/atomic_2.h
libstdc++-v3/include/std/future
libstdc++-v3/src/atomic.cc
libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.c [new file with mode: 0644]
libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc [new file with mode: 0644]

index b19ae1bdfe7735f816a6d3c8b1f032fb2fb5e292..4f8367eaff0eca9a3888b46bea90cfaf264e22e3 100644 (file)
@@ -1,3 +1,16 @@
+2009-10-15  Benjamin Kosnik  <bkoz@redhat.com>
+
+       PR libstdc++/40654
+       PR libstdc++/40826
+       * src/atomic.cc (atomic_flag_test_and_set_explicit): Add
+       static_cast from base to derived.
+       (atomic_flag_clear_explicit): Same.
+       * include/bits/atomic_2.h (__atomic2::atomic_flag): Public derivation.
+       Remove value type constructor.
+       * include/bits/atomic_0.h (__atomic0::atomic_flag): Same.
+       * include/std/future (_Future_state): Use ATOMIC_FLAG_INIT to
+       initialized the atomic_flag member.
+
 2009-10-14  Benjamin Kosnik  <bkoz@redhat.com>
 
        * doc/xml/authors.xml: Update.
index a493ea66af972160c0f927fb1b52eae6fcc0c6a7..0caffaf1e9fb91d3355e2e95498729ed6b0e48f0 100644 (file)
@@ -82,14 +82,15 @@ namespace __atomic0
     __r; })
 
   /// atomic_flag
-  struct atomic_flag : private __atomic_flag_base
+  struct atomic_flag : public __atomic_flag_base
   {
     atomic_flag() = default;
     ~atomic_flag() = default;
     atomic_flag(const atomic_flag&) = delete;
     atomic_flag& operator=(const atomic_flag&) = delete;
 
-    atomic_flag(bool __i) { _M_i = __i; } // XXX deleted copy ctor != agg
+    // Conversion to ATOMIC_FLAG_INIT.
+    atomic_flag(bool __i): __atomic_flag_base({ __i }) { }
 
     bool
     test_and_set(memory_order __m = memory_order_seq_cst) volatile;
index 8e8e7ff16f8cc8667e18b92d1016cb63daa16699..d39adb920a25d4b2927afdf5a2d37afaedc59098 100644 (file)
 namespace __atomic2
 {
   /// atomic_flag
-  struct atomic_flag : private __atomic_flag_base
+  struct atomic_flag : public __atomic_flag_base
   {
     atomic_flag() = default;
     ~atomic_flag() = default;
     atomic_flag(const atomic_flag&) = delete;
     atomic_flag& operator=(const atomic_flag&) = delete;
 
-    atomic_flag(bool __i) { _M_i = __i; } // XXX deleted copy ctor != agg
+    // Conversion to ATOMIC_FLAG_INIT.
+    atomic_flag(bool __i): __atomic_flag_base({ __i }) { }
 
     bool
     test_and_set(memory_order __m = memory_order_seq_cst) volatile
index badb6e07e5a5b9c1f986d829fad31afed1d9ff5b..f922dcd74d5bbf092ffa0e655dac7bfa40b5e3e8 100644 (file)
@@ -150,7 +150,7 @@ namespace std
     typedef _Future_ptr<_Future_result_base>::type _Future_ptr_type;
 
   public:
-    _Future_state() : _M_result(), _M_retrieved(false) { }
+    _Future_state() : _M_result(), _M_retrieved(ATOMIC_FLAG_INIT) { }
 
     _Future_state(const _Future_state&) = delete;
     _Future_state& operator=(const _Future_state&) = delete;
index 3a2ff3d52e927f1d72b40c20a6cfe6db37092446..775bb7601c17ddeaed7e550b8407df889f8e770a 100644 (file)
@@ -80,16 +80,16 @@ namespace std
     atomic_flag_test_and_set_explicit(volatile __atomic_flag_base* __a,
                                      memory_order __m) throw ()
     {
-      volatile atomic_flag d(__a->_M_i);
-      return d.test_and_set(__m);
+      volatile atomic_flag* d = static_cast<volatile atomic_flag*>(__a);
+      return d->test_and_set(__m);
     }
 
     void
     atomic_flag_clear_explicit(volatile __atomic_flag_base* __a,
                               memory_order __m) throw ()
     {
-      volatile atomic_flag d(__a->_M_i);
-      return d.clear(__m);
+      volatile atomic_flag* d = static_cast<volatile atomic_flag*>(__a);
+      return d->clear(__m);
     }
 
     void
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.c b/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.c
new file mode 100644 (file)
index 0000000..3fd2f2c
--- /dev/null
@@ -0,0 +1,34 @@
+// { dg-options "-x c -shared-libgcc -lstdc++" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <cassert>
+#include <stdatomic.h>
+
+// libstdc++/40826
+// libstdc++/40654
+int main()
+{
+  atomic_flag f = ATOMIC_FLAG_INIT;
+
+  atomic_flag_clear(&f); // set to false
+  assert( false == atomic_flag_test_and_set(&f) ); // return previous false, set to true
+  assert( true == atomic_flag_test_and_set(&f) ); // return true
+
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
new file mode 100644 (file)
index 0000000..6cb09f3
--- /dev/null
@@ -0,0 +1,33 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <cstdatomic>
+#include <testsuite_hooks.h>
+
+int main()
+{
+  bool test __attribute__((unused)) = true;
+  std::atomic_flag f = ATOMIC_FLAG_INIT;
+
+  f.clear(); // set to false
+  VERIFY( false == f.test_and_set() ); // return previous false, set to true
+  VERIFY( true == f.test_and_set() ); // return true
+
+  return 0;
+}
This page took 0.082453 seconds and 5 git commands to generate.