diff options
author | fdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-01-08 20:57:57 +0000 |
---|---|---|
committer | fdumont <fdumont@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-01-08 20:57:57 +0000 |
commit | de7466cfbe7bfd81845e88fde48f0b2d1216edb0 (patch) | |
tree | f55b55ed07f3d73ecc9083e0584eae03f77c1141 /libstdc++-v3/include/debug | |
parent | 8a08427dcaa7a3a679a4ac0a832f2b8beacefac4 (diff) | |
download | gcc-de7466cfbe7bfd81845e88fde48f0b2d1216edb0.tar.gz |
2014-01-08 François Dumont <fdumont@gcc.gnu.org>
* include/bits/stl_vector.h (std::vector<>::_M_move_assign): Pass
*this allocator instance when building temporary vector instance
so that *this allocator does not get moved.
* include/debug/safe_base.h
(_Safe_sequence_base(_Safe_sequence_base&&)): New.
* include/debug/vector (__gnu_debug::vector<>(vector&&)): Use new
move constructor from _Safe_sequence_base.
(__gnu_debug::vector<>(vector&&, const allocator_type&)): Swap
safe iterators if the instance is moved.
(__gnu_debug::vector<>::operator=(vector&&)): Likewise.
* testsuite/23_containers/vector/allocator/move.cc (test01): Add
check on a vector iterator.
* testsuite/23_containers/vector/allocator/move_assign.cc
(test02): Likewise.
(test03): New, test with a non-propagating allocator.
* testsuite/23_containers/vector/debug/move_assign_neg.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@206444 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/debug')
-rw-r--r-- | libstdc++-v3/include/debug/safe_base.h | 6 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/vector | 27 |
2 files changed, 23 insertions, 10 deletions
diff --git a/libstdc++-v3/include/debug/safe_base.h b/libstdc++-v3/include/debug/safe_base.h index c2a2b6df97b..4b1d082d264 100644 --- a/libstdc++-v3/include/debug/safe_base.h +++ b/libstdc++-v3/include/debug/safe_base.h @@ -192,6 +192,12 @@ namespace __gnu_debug : _M_iterators(0), _M_const_iterators(0), _M_version(1) { } +#if __cplusplus >= 201103L + _Safe_sequence_base(_Safe_sequence_base&& __x) noexcept + : _Safe_sequence_base() + { _M_swap(__x); } +#endif + /** Notify all iterators that reference this sequence that the sequence is being destroyed. */ ~_Safe_sequence_base() diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index a376f69ff7d..2b750d792a3 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -52,6 +52,7 @@ namespace __debug typedef __gnu_debug::_Equal_to<_Base_const_iterator> _Equal; #if __cplusplus >= 201103L + typedef __gnu_debug::_Safe_sequence<vector<_Tp, _Allocator> > _Safe_base; typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits; #endif @@ -111,18 +112,16 @@ namespace __debug vector(const vector& __x) : _Base(__x), _M_guaranteed_capacity(__x.size()) { } - /// Construction from a release-mode vector + /// Construction from a normal-mode vector vector(const _Base& __x) : _Base(__x), _M_guaranteed_capacity(__x.size()) { } #if __cplusplus >= 201103L vector(vector&& __x) noexcept : _Base(std::move(__x)), + _Safe_base(std::move(__x)), _M_guaranteed_capacity(this->size()) - { - this->_M_swap(__x); - __x._M_guaranteed_capacity = 0; - } + { __x._M_guaranteed_capacity = 0; } vector(const vector& __x, const allocator_type& __a) : _Base(__x, __a), _M_guaranteed_capacity(__x.size()) { } @@ -131,7 +130,10 @@ namespace __debug : _Base(std::move(__x), __a), _M_guaranteed_capacity(this->size()) { - __x._M_invalidate_all(); + if (__x.get_allocator() == __a) + this->_M_swap(__x); + else + __x._M_invalidate_all(); __x._M_guaranteed_capacity = 0; } @@ -146,7 +148,7 @@ namespace __debug vector& operator=(const vector& __x) { - static_cast<_Base&>(*this) = __x; + _M_base() = __x; this->_M_invalidate_all(); _M_update_guaranteed_capacity(); return *this; @@ -157,8 +159,13 @@ namespace __debug operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move()) { __glibcxx_check_self_move_assign(__x); - _Base::operator=(std::move(__x)); - this->_M_invalidate_all(); + bool xfer_memory = _Alloc_traits::_S_propagate_on_move_assign() + || __x.get_allocator() == this->get_allocator(); + _M_base() = std::move(__x._M_base()); + if (xfer_memory) + this->_M_swap(__x); + else + this->_M_invalidate_all(); _M_update_guaranteed_capacity(); __x._M_invalidate_all(); __x._M_guaranteed_capacity = 0; @@ -168,7 +175,7 @@ namespace __debug vector& operator=(initializer_list<value_type> __l) { - static_cast<_Base&>(*this) = __l; + _M_base() = __l; this->_M_invalidate_all(); _M_update_guaranteed_capacity(); return *this; |