From 68d047cb48654a89da139e03c6c5e424734a194e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Dumont?= Date: Fri, 8 Mar 2013 20:08:20 +0000 Subject: [PATCH] vector.tcc (vector<>operator=(const vector<>&): Reset pointers after deallocation when memory can be reused. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2013-03-08 François Dumont * include/bits/vector.tcc (vector<>operator=(const vector<>&): Reset pointers after deallocation when memory can be reused. * testsuite/23_containers/vector/allocator/minimal.cc: Insert elements to really challenge C++11 allocator integration. * testsuite/23_containers/vector/allocator/copy.cc: Likewise. * testsuite/23_containers/vector/allocator/copy_assign.cc: Likewise. * testsuite/23_containers/vector/allocator/move_assign.cc: Likewise. * testsuite/23_containers/vector/allocator/swap.cc: Likewise and swap vector back before checks on memory/personality mapping are performed. * testsuite/23_containers/forward_list/allocator/minimal.cc: Insert element to really challenge C++11 allocator integration. * testsuite/23_containers/forward_list/allocator/copy.cc: Likewise. * testsuite/23_containers/forward_list/allocator/copy_assign.cc: Likewise. * testsuite/23_containers/forward_list/allocator/move_assign.cc: Likewise. * testsuite/23_containers/forward_list/allocator/swap.cc: Likewise and swap forward_list back before checks on memory/personality mapping are performed. From-SVN: r196557 --- libstdc++-v3/ChangeLog | 26 +++++++++++++++++++ libstdc++-v3/include/bits/vector.tcc | 3 +++ .../forward_list/allocator/copy.cc | 2 ++ .../forward_list/allocator/copy_assign.cc | 4 +++ .../forward_list/allocator/minimal.cc | 1 + .../forward_list/allocator/move_assign.cc | 4 +++ .../forward_list/allocator/swap.cc | 6 +++++ .../23_containers/vector/allocator/copy.cc | 2 ++ .../vector/allocator/copy_assign.cc | 4 +++ .../23_containers/vector/allocator/minimal.cc | 1 + .../vector/allocator/move_assign.cc | 4 +++ .../23_containers/vector/allocator/swap.cc | 4 +++ 12 files changed, 61 insertions(+) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 3e1a53eb1ec..342c6a42d62 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,29 @@ +2013-03-08 François Dumont + + * include/bits/vector.tcc (vector<>operator=(const vector<>&): + Reset pointers after deallocation when memory can be reused. + * testsuite/23_containers/vector/allocator/minimal.cc: Insert + elements to really challenge C++11 allocator integration. + * testsuite/23_containers/vector/allocator/copy.cc: Likewise. + * testsuite/23_containers/vector/allocator/copy_assign.cc: + Likewise. + * testsuite/23_containers/vector/allocator/move_assign.cc: + Likewise. + * testsuite/23_containers/vector/allocator/swap.cc: Likewise and + swap vector back before checks on memory/personality mapping are + performed. + * testsuite/23_containers/forward_list/allocator/minimal.cc: + Insert element to really challenge C++11 allocator integration. + * testsuite/23_containers/forward_list/allocator/copy.cc: + Likewise. + * testsuite/23_containers/forward_list/allocator/copy_assign.cc: + Likewise. + * testsuite/23_containers/forward_list/allocator/move_assign.cc: + Likewise. + * testsuite/23_containers/forward_list/allocator/swap.cc: Likewise + and swap forward_list back before checks on memory/personality + mapping are performed. + 2013-03-07 Jakub Jelinek * config/abi/post/i386-linux-gnu/baseline_symbols.txt: Update. diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index d48412ae65d..0882fe6884a 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -173,6 +173,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage - this->_M_impl._M_start); + this->_M_impl._M_start = nullptr; + this->_M_impl._M_finish = nullptr; + this->_M_impl._M_end_of_storage = nullptr; } std::__alloc_on_copy(_M_get_Tp_allocator(), __x._M_get_Tp_allocator()); diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/copy.cc b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/copy.cc index 0c66c5153f2..f7e781ce9ec 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/copy.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/copy.cc @@ -31,6 +31,7 @@ void test01() typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(0 == v2.get_allocator().get_personality()); @@ -42,6 +43,7 @@ void test02() typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/copy_assign.cc b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/copy_assign.cc index 6f0f8e3bd11..e673b2e9e00 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/copy_assign.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/copy_assign.cc @@ -31,7 +31,9 @@ void test01() typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); v2 = v1; VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); @@ -43,7 +45,9 @@ void test02() typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); v2 = v1; VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/minimal.cc index f6caecc1165..4d2a97856e0 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/minimal.cc @@ -37,6 +37,7 @@ void test01() typedef std::allocator_traits traits_type; typedef std::forward_list test_type; test_type v(alloc_type{}); + v.push_front(T()); VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); } diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/move_assign.cc b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/move_assign.cc index ae85f876670..b3532392cb9 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/move_assign.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/move_assign.cc @@ -31,7 +31,9 @@ void test01() typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); v2 = std::move(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); @@ -43,7 +45,9 @@ void test02() typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); v2 = std::move(v1); VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/swap.cc b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/swap.cc index a2e70b79862..b5b4480264b 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/allocator/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/allocator/swap.cc @@ -48,10 +48,14 @@ void test01() typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); std::swap(v1, v2); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); + // swap back so assertions in uneq_allocator::deallocate don't fail + std::swap(v1, v2); } void test02() @@ -60,7 +64,9 @@ void test02() typedef propagating_allocator alloc_type; typedef std::forward_list test_type; test_type v1(alloc_type(1)); + v1.push_front(T()); test_type v2(alloc_type(2)); + v2.push_front(T()); std::swap(v1, v2); VERIFY(2 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); diff --git a/libstdc++-v3/testsuite/23_containers/vector/allocator/copy.cc b/libstdc++-v3/testsuite/23_containers/vector/allocator/copy.cc index 5621a29e40f..f95c345b853 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/allocator/copy.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/allocator/copy.cc @@ -31,6 +31,7 @@ void test01() typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(0 == v2.get_allocator().get_personality()); @@ -42,6 +43,7 @@ void test02() typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); diff --git a/libstdc++-v3/testsuite/23_containers/vector/allocator/copy_assign.cc b/libstdc++-v3/testsuite/23_containers/vector/allocator/copy_assign.cc index 49df3606185..89aac6f56da 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/allocator/copy_assign.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/allocator/copy_assign.cc @@ -31,7 +31,9 @@ void test01() typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(alloc_type(2)); + v2.push_back(T()); v2 = v1; VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); @@ -43,7 +45,9 @@ void test02() typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(alloc_type(2)); + v2.push_back(T()); v2 = v1; VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); diff --git a/libstdc++-v3/testsuite/23_containers/vector/allocator/minimal.cc b/libstdc++-v3/testsuite/23_containers/vector/allocator/minimal.cc index e2600ae322b..1b66b50973a 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/allocator/minimal.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/allocator/minimal.cc @@ -35,6 +35,7 @@ void test01() typedef std::allocator_traits traits_type; typedef std::vector test_type; test_type v(alloc_type{}); + v.push_back(T()); VERIFY( v.max_size() == traits_type::max_size(v.get_allocator()) ); } diff --git a/libstdc++-v3/testsuite/23_containers/vector/allocator/move_assign.cc b/libstdc++-v3/testsuite/23_containers/vector/allocator/move_assign.cc index 6544493f512..64795d361c9 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/allocator/move_assign.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/allocator/move_assign.cc @@ -31,7 +31,9 @@ void test01() typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(alloc_type(2)); + v2.push_back(T()); v2 = std::move(v1); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); @@ -43,8 +45,10 @@ void test02() typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(alloc_type(2)); v2 = std::move(v1); + v2.push_back(T()); VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality()); } diff --git a/libstdc++-v3/testsuite/23_containers/vector/allocator/swap.cc b/libstdc++-v3/testsuite/23_containers/vector/allocator/swap.cc index 70822c35a91..ce44cf80f88 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/allocator/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/allocator/swap.cc @@ -48,10 +48,14 @@ void test01() typedef propagating_allocator alloc_type; typedef std::vector test_type; test_type v1(alloc_type(1)); + v1.push_back(T()); test_type v2(alloc_type(2)); + v2.push_back(T()); std::swap(v1, v2); VERIFY(1 == v1.get_allocator().get_personality()); VERIFY(2 == v2.get_allocator().get_personality()); + // swap back so assertions in uneq_allocator::deallocate don't fail + std::swap(v1, v2); } void test02() -- 2.30.2