Apparently when adding allocator propagation to std::deque I didn't read my own comment in this constructor:
_Deque_base(const allocator_type& __a) : _M_impl(__a) { /* Caller must initialize map. */ } This adds the missing initialization. Tested ppc64le-linux, committed to trunk. This needs to be backported to gcc-5-branch too.
commit 386b9e9d927e5d0bcca8815b6219581ea58723bf Author: Jonathan Wakely <jwak...@redhat.com> Date: Thu Sep 24 16:10:27 2015 +0100 Leave moved-from std::deque in a valid state 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. diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index f674245..f81ffd9 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -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); diff --git a/libstdc++-v3/testsuite/23_containers/deque/allocator/move.cc b/libstdc++-v3/testsuite/23_containers/deque/allocator/move.cc index c858437..1b8a0e4 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/allocator/move.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/allocator/move.cc @@ -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()