Leave moved-from std::deque in a valid state
authorJonathan Wakely <jwakely@redhat.com>
Thu, 24 Sep 2015 15:46:24 +0000 (16:46 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 24 Sep 2015 15:46:24 +0000 (16:46 +0100)
PR libstdc++/67707
* include/bits/stl_deque.h (_Deque_base::_M_move_impl): Initialize
empty object.
* testsuite/23_containers/deque/allocator/move.cc: Check moved-from
deque.

From-SVN: r228090

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_deque.h
libstdc++-v3/testsuite/23_containers/deque/allocator/move.cc

index 17d82e3de71ab4014c2838d008d66ef6231780a3..24a60508cce981fe1797615d0e759395eabf5398 100644 (file)
@@ -1,3 +1,11 @@
+2015-09-24  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/67707
+       * include/bits/stl_deque.h (_Deque_base::_M_move_impl): Initialize
+       empty object.
+       * testsuite/23_containers/deque/allocator/move.cc: Check moved-from
+       deque.
+
 2015-09-23  Jonathan Wakely  <jwakely@redhat.com>
 
        * src/filesystem/ops.cc (canonical): Simplify error handling and
index f674245b30dba7adb8df96ace1a36cc79e9828bd..f81ffd97d33fb1015e3f791be22b4019568fc5fc 100644 (file)
@@ -644,6 +644,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        _Tp_alloc_type __sink __attribute((__unused__)) {std::move(__alloc)};
        // Create an empty map that allocates using the moved-from allocator.
        _Deque_base __empty{__alloc};
+       __empty._M_initialize_map(0);
        // Now safe to modify current allocator and perform non-throwing swaps.
        _Deque_impl __ret{std::move(_M_get_Tp_allocator())};
        _M_impl._M_swap_data(__ret);
index c8584378cb09a53c040daff6e96171004d16531e..1b8a0e4e2fb2bdda860af637fcb9814c361f9233 100644 (file)
@@ -36,6 +36,11 @@ void test01()
   VERIFY(1 == v1.get_allocator().get_personality());
   VERIFY(1 == v2.get_allocator().get_personality());
   VERIFY( it == v2.begin() );
+
+  // PR libstdc++/67707
+  VERIFY( v1.size() == 0 );
+  v1 = test_type();
+  VERIFY( v1.size() == 0 );
 }
 
 void test02()
@@ -47,6 +52,11 @@ void test02()
   test_type v2(std::move(v1), alloc_type(2));
   VERIFY(1 == v1.get_allocator().get_personality());
   VERIFY(2 == v2.get_allocator().get_personality());
+
+  // PR libstdc++/67707
+  VERIFY( v1.size() == 0 );
+  v1 = test_type();
+  VERIFY( v1.size() == 0 );
 }
 
 int main()