Commit 935469da by François Dumont

Move from state of allocators (LWG2593)

2019-05-17  François Dumont  <fdumont@gcc.gnu.org>

	Move from state of allocators (LWG2593)
	* include/bits/stl_deque.h
	(_Deque_base(_Deque_base&&, false_type)): Remove.
	(_Deque_base(_Deque_base&&, true_type)): Remove.
	(_Deque_base(_Deque_base&&)): Adapt.
	(_Deque_base::_M_move_impl()): Remove.
	* testsuite/util/testsuite_allocator.h
	(propagating_allocator(propagating_allocator&&)): Preserve move from
	state.
	* testsuite/23_containers/deque/allocator/move_assign.cc (test02):
	Adapt.
	* testsuite/23_containers/forward_list/allocator/move_assign.cc (test02):
	Adapt.
	* testsuite/23_containers/list/allocator/move_assign.cc (test02): Adapt.
	* testsuite/23_containers/map/allocator/move_assign.cc (test02): Adapt.
	* testsuite/23_containers/multimap/allocator/move_assign.cc (test02):
	Adapt.
	* testsuite/23_containers/multiset/allocator/move_assign.cc (test02):
	Adapt.
	* testsuite/23_containers/set/allocator/move_assign.cc (test02): Adapt.
	* testsuite/23_containers/unordered_map/allocator/move_assign.cc
	(test02): Adapt.
	* testsuite/23_containers/unordered_multimap/allocator/move_assign.cc
	(test02): Adapt.
	* testsuite/23_containers/unordered_multiset/allocator/move_assign.cc
	(test02): Adapt.
	* testsuite/23_containers/unordered_set/allocator/move_assign.cc
	(test02): Adapt.
	* testsuite/23_containers/vector/allocator/move_assign.cc (test02):
	Adapt.
	* testsuite/23_containers/vector/bool/allocator/move_assign.cc (test02):
	Adapt.
	* testsuite/21_strings/basic_string/allocator/char/move_assign.cc
	(test02): Adapt.
	* testsuite/21_strings/basic_string/allocator/wchar_t/move_assign.cc
	(test02): Adapt.

From-SVN: r271309
parent 395389bf
2019-05-17 François Dumont <fdumont@gcc.gnu.org>
Move from state of allocators (LWG2593)
* include/bits/stl_deque.h
(_Deque_base(_Deque_base&&, false_type)): Remove.
(_Deque_base(_Deque_base&&, true_type)): Remove.
(_Deque_base(_Deque_base&&)): Adapt.
(_Deque_base::_M_move_impl()): Remove.
* testsuite/util/testsuite_allocator.h
(propagating_allocator(propagating_allocator&&)): Preserve move from
state.
* testsuite/23_containers/deque/allocator/move_assign.cc (test02):
Adapt.
* testsuite/23_containers/forward_list/allocator/move_assign.cc (test02):
Adapt.
* testsuite/23_containers/list/allocator/move_assign.cc (test02): Adapt.
* testsuite/23_containers/map/allocator/move_assign.cc (test02): Adapt.
* testsuite/23_containers/multimap/allocator/move_assign.cc (test02):
Adapt.
* testsuite/23_containers/multiset/allocator/move_assign.cc (test02):
Adapt.
* testsuite/23_containers/set/allocator/move_assign.cc (test02): Adapt.
* testsuite/23_containers/unordered_map/allocator/move_assign.cc
(test02): Adapt.
* testsuite/23_containers/unordered_multimap/allocator/move_assign.cc
(test02): Adapt.
* testsuite/23_containers/unordered_multiset/allocator/move_assign.cc
(test02): Adapt.
* testsuite/23_containers/unordered_set/allocator/move_assign.cc
(test02): Adapt.
* testsuite/23_containers/vector/allocator/move_assign.cc (test02):
Adapt.
* testsuite/23_containers/vector/bool/allocator/move_assign.cc (test02):
Adapt.
* testsuite/21_strings/basic_string/allocator/char/move_assign.cc
(test02): Adapt.
* testsuite/21_strings/basic_string/allocator/wchar_t/move_assign.cc
(test02): Adapt.
2019-05-16 Jonathan Wakely <jwakely@redhat.com> 2019-05-16 Jonathan Wakely <jwakely@redhat.com>
* src/c++17/fs_ops.cc (absolute(const path&, error_code&)) * src/c++17/fs_ops.cc (absolute(const path&, error_code&))
......
...@@ -500,11 +500,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -500,11 +500,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ /* Caller must initialize map. */ } { /* Caller must initialize map. */ }
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
_Deque_base(_Deque_base&& __x, false_type) _Deque_base(_Deque_base&& __x)
: _M_impl(__x._M_move_impl())
{ }
_Deque_base(_Deque_base&& __x, true_type)
: _M_impl(std::move(__x._M_get_Tp_allocator())) : _M_impl(std::move(__x._M_get_Tp_allocator()))
{ {
_M_initialize_map(0); _M_initialize_map(0);
...@@ -512,10 +508,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -512,10 +508,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
this->_M_impl._M_swap_data(__x._M_impl); this->_M_impl._M_swap_data(__x._M_impl);
} }
_Deque_base(_Deque_base&& __x)
: _Deque_base(std::move(__x), typename _Alloc_traits::is_always_equal{})
{ }
_Deque_base(_Deque_base&& __x, const allocator_type& __a, size_t __n) _Deque_base(_Deque_base&& __x, const allocator_type& __a, size_t __n)
: _M_impl(__a) : _M_impl(__a)
{ {
...@@ -627,29 +619,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -627,29 +619,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
enum { _S_initial_map_size = 8 }; enum { _S_initial_map_size = 8 };
_Deque_impl _M_impl; _Deque_impl _M_impl;
#if __cplusplus >= 201103L
private:
_Deque_impl
_M_move_impl()
{
if (!_M_impl._M_map)
return std::move(_M_impl);
// Create a copy of the current allocator.
_Tp_alloc_type __alloc{_M_get_Tp_allocator()};
// Put that copy in a moved-from state.
_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);
_M_impl._M_swap_data(__empty._M_impl);
return __ret;
}
#endif
}; };
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
......
...@@ -80,7 +80,7 @@ void test02() ...@@ -80,7 +80,7 @@ void test02()
test_type v2(alloc_type(2)); test_type v2(alloc_type(2));
v2.assign(1, c); v2.assign(1, c);
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
test_type v3(alloc_type(3)); test_type v3(alloc_type(3));
...@@ -88,7 +88,7 @@ void test02() ...@@ -88,7 +88,7 @@ void test02()
test_type v4(alloc_type(4)); test_type v4(alloc_type(4));
v4.assign(100, c); v4.assign(100, c);
v4 = std::move(v3); v4 = std::move(v3);
VERIFY(0 == v3.get_allocator().get_personality()); VERIFY(3 == v3.get_allocator().get_personality());
VERIFY(3 == v4.get_allocator().get_personality()); VERIFY(3 == v4.get_allocator().get_personality());
test_type v5(alloc_type(5)); test_type v5(alloc_type(5));
...@@ -96,7 +96,7 @@ void test02() ...@@ -96,7 +96,7 @@ void test02()
test_type v6(alloc_type(6)); test_type v6(alloc_type(6));
v6.assign(1, c); v6.assign(1, c);
v6 = std::move(v5); v6 = std::move(v5);
VERIFY(0 == v5.get_allocator().get_personality()); VERIFY(5 == v5.get_allocator().get_personality());
VERIFY(5 == v6.get_allocator().get_personality()); VERIFY(5 == v6.get_allocator().get_personality());
test_type v7(alloc_type(7)); test_type v7(alloc_type(7));
...@@ -104,7 +104,7 @@ void test02() ...@@ -104,7 +104,7 @@ void test02()
test_type v8(alloc_type(8)); test_type v8(alloc_type(8));
v8.assign(100, c); v8.assign(100, c);
v8 = std::move(v7); v8 = std::move(v7);
VERIFY(0 == v7.get_allocator().get_personality()); VERIFY(7 == v7.get_allocator().get_personality());
VERIFY(7 == v8.get_allocator().get_personality()); VERIFY(7 == v8.get_allocator().get_personality());
} }
......
...@@ -80,7 +80,7 @@ void test02() ...@@ -80,7 +80,7 @@ void test02()
test_type v2(alloc_type(2)); test_type v2(alloc_type(2));
v2.assign(1, c); v2.assign(1, c);
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
test_type v3(alloc_type(3)); test_type v3(alloc_type(3));
...@@ -88,7 +88,7 @@ void test02() ...@@ -88,7 +88,7 @@ void test02()
test_type v4(alloc_type(4)); test_type v4(alloc_type(4));
v4.assign(100, c); v4.assign(100, c);
v4 = std::move(v3); v4 = std::move(v3);
VERIFY(0 == v3.get_allocator().get_personality()); VERIFY(3 == v3.get_allocator().get_personality());
VERIFY(3 == v4.get_allocator().get_personality()); VERIFY(3 == v4.get_allocator().get_personality());
test_type v5(alloc_type(5)); test_type v5(alloc_type(5));
...@@ -96,7 +96,7 @@ void test02() ...@@ -96,7 +96,7 @@ void test02()
test_type v6(alloc_type(6)); test_type v6(alloc_type(6));
v6.assign(1, c); v6.assign(1, c);
v6 = std::move(v5); v6 = std::move(v5);
VERIFY(0 == v5.get_allocator().get_personality()); VERIFY(5 == v5.get_allocator().get_personality());
VERIFY(5 == v6.get_allocator().get_personality()); VERIFY(5 == v6.get_allocator().get_personality());
test_type v7(alloc_type(7)); test_type v7(alloc_type(7));
...@@ -104,7 +104,7 @@ void test02() ...@@ -104,7 +104,7 @@ void test02()
test_type v8(alloc_type(8)); test_type v8(alloc_type(8));
v8.assign(100, c); v8.assign(100, c);
v8 = std::move(v7); v8 = std::move(v7);
VERIFY(0 == v7.get_allocator().get_personality()); VERIFY(7 == v7.get_allocator().get_personality());
VERIFY(7 == v8.get_allocator().get_personality()); VERIFY(7 == v8.get_allocator().get_personality());
} }
......
...@@ -45,7 +45,7 @@ void test02() ...@@ -45,7 +45,7 @@ void test02()
test_type v2(1, alloc_type(2)); test_type v2(1, alloc_type(2));
v2 = std::move(v1); v2 = std::move(v1);
VERIFY( it == v2.begin() ); VERIFY( it == v2.begin() );
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
} }
......
...@@ -48,7 +48,7 @@ void test02() ...@@ -48,7 +48,7 @@ void test02()
test_type v2(alloc_type(2)); test_type v2(alloc_type(2));
v2.push_front(T()); v2.push_front(T());
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( it == v2.begin() ); VERIFY( it == v2.begin() );
} }
......
...@@ -48,7 +48,7 @@ void test02() ...@@ -48,7 +48,7 @@ void test02()
test_type v2(alloc_type(2)); test_type v2(alloc_type(2));
v2.push_front(T()); v2.push_front(T());
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( it == v2.begin() ); VERIFY( it == v2.begin() );
} }
......
...@@ -58,7 +58,7 @@ void test02() ...@@ -58,7 +58,7 @@ void test02()
v2 = { test_type::value_type{} }; v2 = { test_type::value_type{} };
v2 = std::move(v1); v2 = std::move(v1);
VERIFY( 0 == v1.get_allocator().get_personality() ); VERIFY( 1 == v1.get_allocator().get_personality() );
VERIFY( 1 == v2.get_allocator().get_personality() ); VERIFY( 1 == v2.get_allocator().get_personality() );
VERIFY( it == v2.begin() ); VERIFY( it == v2.begin() );
} }
......
...@@ -54,7 +54,7 @@ void test02() ...@@ -54,7 +54,7 @@ void test02()
test_type v2(alloc_type(2)); test_type v2(alloc_type(2));
v2 = { test_type::value_type{} }; v2 = { test_type::value_type{} };
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( it == v2.begin() ); VERIFY( it == v2.begin() );
} }
......
...@@ -52,7 +52,7 @@ void test02() ...@@ -52,7 +52,7 @@ void test02()
test_type v2(alloc_type(2)); test_type v2(alloc_type(2));
v2 = { test_type::value_type{} }; v2 = { test_type::value_type{} };
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( it == v2.begin() ); VERIFY( it == v2.begin() );
} }
......
...@@ -55,7 +55,7 @@ void test02() ...@@ -55,7 +55,7 @@ void test02()
test_type v2(alloc_type(2)); test_type v2(alloc_type(2));
v2 = { test_type::value_type{} }; v2 = { test_type::value_type{} };
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( it == v2.begin() ); VERIFY( it == v2.begin() );
} }
......
...@@ -76,7 +76,7 @@ void test02() ...@@ -76,7 +76,7 @@ void test02()
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( counter_type::move_assign_count == 0 ); VERIFY( counter_type::move_assign_count == 0 );
......
...@@ -76,7 +76,7 @@ void test02() ...@@ -76,7 +76,7 @@ void test02()
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( counter_type::move_assign_count == 0 ); VERIFY( counter_type::move_assign_count == 0 );
......
...@@ -70,7 +70,7 @@ void test02() ...@@ -70,7 +70,7 @@ void test02()
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( counter_type::move_count == 0 ); VERIFY( counter_type::move_count == 0 );
......
...@@ -86,7 +86,7 @@ void test02() ...@@ -86,7 +86,7 @@ void test02()
v2 = std::move(v1); v2 = std::move(v1);
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
VERIFY( counter_type::move_count == 0 ); VERIFY( counter_type::move_count == 0 );
......
...@@ -49,7 +49,7 @@ void test02() ...@@ -49,7 +49,7 @@ void test02()
v2.push_back(T()); v2.push_back(T());
v2 = std::move(v1); v2 = std::move(v1);
VERIFY( it == v2.begin() ); VERIFY( it == v2.begin() );
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
} }
......
...@@ -49,7 +49,7 @@ void test02() ...@@ -49,7 +49,7 @@ void test02()
v2.push_back(T()); v2.push_back(T());
v2 = std::move(v1); v2 = std::move(v1);
VERIFY( it == v2.begin() ); VERIFY( it == v2.begin() );
VERIFY(0 == v1.get_allocator().get_personality()); VERIFY(1 == v1.get_allocator().get_personality());
VERIFY(1 == v2.get_allocator().get_personality()); VERIFY(1 == v2.get_allocator().get_personality());
} }
......
...@@ -465,12 +465,12 @@ namespace __gnu_test ...@@ -465,12 +465,12 @@ namespace __gnu_test
return *this; return *this;
} }
// postcondition: a.get_personality() == 0 // postcondition: LWG2593 a.get_personality() un-changed.
propagating_allocator(propagating_allocator&& a) noexcept propagating_allocator(propagating_allocator&& a) noexcept
: base_alloc() : base_alloc(std::move(a.base()))
{ swap_base(a); } { }
// postcondition: a.get_personality() == 0 // postcondition: LWG2593 a.get_personality() un-changed
propagating_allocator& propagating_allocator&
operator=(propagating_allocator&& a) noexcept operator=(propagating_allocator&& a) noexcept
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment