diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2019-10-23 17:14:28 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-10-23 17:14:28 +0100 |
commit | 603aec6775d5191fafd57412364578db68432f74 (patch) | |
tree | eecdf7326f959268b1d3a3dc997d14369a6b8f5a /libstdc++-v3 | |
parent | 2ccbd21ded6eae4e099ccb1b5952dd3337875087 (diff) | |
download | gcc-603aec6775d5191fafd57412364578db68432f74.zip gcc-603aec6775d5191fafd57412364578db68432f74.tar.gz gcc-603aec6775d5191fafd57412364578db68432f74.tar.bz2 |
Adjust extension types to use allocator_traits
This makes these extensions work with types meeting the Cpp17Allocator
requirements as well as the C++98 Allocator requirements.
* include/backward/hash_set (hash_set): Use __alloc_traits.
* include/backward/hashtable.h (_Hashtable): Likewise.
* include/ext/alloc_traits.h (__alloc_traits::allocate): Add overload
taking a hint.
* include/ext/extptr_allocator.h (_ExtPtr_allocator::allocate): Ignore
hint.
* include/ext/slist (_Slist_base): Use __alloc_traits.
* include/tr1/hashtable.h (_Hashtable): Likewise.
* include/tr1/regex (match_results): Use vector::const_reference
instead of assuming the allocator defines it.
* testsuite/backward/hash_map/23528.cc: Use allocator_traits in C++11.
* testsuite/tr1/6_containers/unordered_map/capacity/29134-map.cc: Use
__gnu_test::max_size.
* testsuite/tr1/6_containers/unordered_multimap/capacity/
29134-multimap.cc: Likewise.
* testsuite/tr1/6_containers/unordered_multiset/capacity/
29134-multiset.cc: Likewise.
* testsuite/tr1/6_containers/unordered_set/capacity/29134-set.cc:
Likewise.
From-SVN: r277335
Diffstat (limited to 'libstdc++-v3')
13 files changed, 97 insertions, 37 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 87ee636..9f19e4f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,25 @@ +2019-10-23 Jonathan Wakely <jwakely@redhat.com> + + * include/backward/hash_set (hash_set): Use __alloc_traits. + * include/backward/hashtable.h (_Hashtable): Likewise. + * include/ext/alloc_traits.h (__alloc_traits::allocate): Add overload + taking a hint. + * include/ext/extptr_allocator.h (_ExtPtr_allocator::allocate): Ignore + hint. + * include/ext/slist (_Slist_base): Use __alloc_traits. + * include/tr1/hashtable.h (_Hashtable): Likewise. + * include/tr1/regex (match_results): Use vector::const_reference + instead of assuming the allocator defines it. + * testsuite/backward/hash_map/23528.cc: Use allocator_traits in C++11. + * testsuite/tr1/6_containers/unordered_map/capacity/29134-map.cc: Use + __gnu_test::max_size. + * testsuite/tr1/6_containers/unordered_multimap/capacity/ + 29134-multimap.cc: Likewise. + * testsuite/tr1/6_containers/unordered_multiset/capacity/ + 29134-multiset.cc: Likewise. + * testsuite/tr1/6_containers/unordered_set/capacity/29134-set.cc: + Likewise. + 2019-10-22 Jonathan Wakely <jwakely@redhat.com> * testsuite/util/testsuite_abi.h: Restore use of tr1/unordered_map diff --git a/libstdc++-v3/include/backward/hash_set b/libstdc++-v3/include/backward/hash_set index 1445aa6..7f743fd 100644 --- a/libstdc++-v3/include/backward/hash_set +++ b/libstdc++-v3/include/backward/hash_set @@ -88,6 +88,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __glibcxx_class_requires3(_HashFcn, size_t, _Value, _UnaryFunctionConcept) __glibcxx_class_requires3(_EqualKey, _Value, _Value, _BinaryPredicateConcept) + typedef __alloc_traits<_Alloc> _Alloc_traits; + private: typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>, _EqualKey, _Alloc> _Ht; @@ -101,10 +103,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef typename _Ht::size_type size_type; typedef typename _Ht::difference_type difference_type; - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; - typedef typename _Alloc::reference reference; - typedef typename _Alloc::const_reference const_reference; + typedef typename _Alloc_traits::pointer pointer; + typedef typename _Alloc_traits::const_pointer const_pointer; + typedef typename _Alloc_traits::reference reference; + typedef typename _Alloc_traits::const_reference const_reference; typedef typename _Ht::const_iterator iterator; typedef typename _Ht::const_iterator const_iterator; diff --git a/libstdc++-v3/include/backward/hashtable.h b/libstdc++-v3/include/backward/hashtable.h index df6ad85..cfb9cf9 100644 --- a/libstdc++-v3/include/backward/hashtable.h +++ b/libstdc++-v3/include/backward/hashtable.h @@ -63,6 +63,7 @@ #include <iterator> #include <algorithm> #include <bits/stl_function.h> +#include <ext/alloc_traits.h> #include <backward/hash_fun.h> namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) @@ -280,14 +281,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef _Hashtable_node<_Val> _Node; public: - typedef typename _Alloc::template rebind<value_type>::other allocator_type; + typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template + rebind<value_type>::other allocator_type; + allocator_type get_allocator() const { return _M_node_allocator; } private: - typedef typename _Alloc::template rebind<_Node>::other _Node_Alloc; - typedef typename _Alloc::template rebind<_Node*>::other _Nodeptr_Alloc; + typedef __gnu_cxx::__alloc_traits<allocator_type> _Alloc_traits; + typedef typename _Alloc_traits::template rebind<_Node>::other + _Node_Alloc; + typedef typename _Alloc_traits::template rebind<_Node*>::other + _Nodeptr_Alloc; typedef std::vector<_Node*, _Nodeptr_Alloc> _Vector_type; _Node_Alloc _M_node_allocator; @@ -608,7 +614,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __n->_M_next = 0; __try { - this->get_allocator().construct(&__n->_M_val, __obj); + allocator_type __a = this->get_allocator(); + _Alloc_traits::construct(__a, &__n->_M_val, __obj); return __n; } __catch(...) @@ -621,7 +628,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void _M_delete_node(_Node* __n) { - this->get_allocator().destroy(&__n->_M_val); + allocator_type __a = this->get_allocator(); + _Alloc_traits::destroy(__a, &__n->_M_val); _M_put_node(__n); } diff --git a/libstdc++-v3/include/ext/alloc_traits.h b/libstdc++-v3/include/ext/alloc_traits.h index 65fa3de..65340eb 100644 --- a/libstdc++-v3/include/ext/alloc_traits.h +++ b/libstdc++-v3/include/ext/alloc_traits.h @@ -132,6 +132,11 @@ template<typename _Alloc, typename = typename _Alloc::value_type> allocate(_Alloc& __a, size_type __n) { return __a.allocate(__n); } + template<typename _Hint> + _GLIBCXX_NODISCARD static pointer + allocate(_Alloc& __a, size_type __n, _Hint __hint) + { return __a.allocate(__n, __hint); } + static void deallocate(_Alloc& __a, pointer __p, size_type __n) { __a.deallocate(__p, __n); } diff --git a/libstdc++-v3/include/ext/extptr_allocator.h b/libstdc++-v3/include/ext/extptr_allocator.h index 2ce87b60..4e86fef 100644 --- a/libstdc++-v3/include/ext/extptr_allocator.h +++ b/libstdc++-v3/include/ext/extptr_allocator.h @@ -92,8 +92,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const_pointer address(const_reference __x) const _GLIBCXX_NOEXCEPT { return std::__addressof(__x); } - _GLIBCXX_NODISCARD pointer allocate(size_type __n, void* __hint = 0) - { return _M_real_alloc.allocate(__n,__hint); } + _GLIBCXX_NODISCARD pointer allocate(size_type __n, const void* = 0) + { return _M_real_alloc.allocate(__n); } void deallocate(pointer __p, size_type __n) { _M_real_alloc.deallocate(__p.get(), __n); } diff --git a/libstdc++-v3/include/ext/slist b/libstdc++-v3/include/ext/slist index 93522ca..cbdfae0 100644 --- a/libstdc++-v3/include/ext/slist +++ b/libstdc++-v3/include/ext/slist @@ -49,6 +49,7 @@ #include <bits/stl_construct.h> #include <bits/stl_uninitialized.h> #include <bits/concept_check.h> +#include <ext/alloc_traits.h> namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) { @@ -251,7 +252,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Slist_node<_Tp>* __next = (_Slist_node<_Tp>*) (__pos->_M_next); _Slist_node_base* __next_next = __next->_M_next; __pos->_M_next = __next_next; - get_allocator().destroy(&__next->_M_data); + allocator_type __a = get_allocator(); + __alloc_traits<allocator_type>::destroy(__a, &__next->_M_data); _M_put_node(__next); return __next_next; } @@ -268,7 +270,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _Slist_node<_Tp>* __tmp = __cur; __cur = (_Slist_node<_Tp>*) __cur->_M_next; - get_allocator().destroy(&__tmp->_M_data); + allocator_type __a = get_allocator(); + __alloc_traits<allocator_type>::destroy(__a, &__tmp->_M_data); _M_put_node(__tmp); } __before_first->_M_next = __last_node; @@ -318,7 +321,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Node* __node = this->_M_get_node(); __try { - get_allocator().construct(&__node->_M_data, __x); + allocator_type __a = get_allocator(); + __alloc_traits<allocator_type>::construct(__a, &__node->_M_data, + __x); __node->_M_next = 0; } __catch(...) @@ -335,7 +340,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Node* __node = this->_M_get_node(); __try { - get_allocator().construct(&__node->_M_data, value_type()); + allocator_type __a = get_allocator(); + __alloc_traits<allocator_type>::construct(__a, &__node->_M_data, + value_type()); __node->_M_next = 0; } __catch(...) @@ -481,7 +488,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _Node* __node = (_Node*) this->_M_head._M_next; this->_M_head._M_next = __node->_M_next; - get_allocator().destroy(&__node->_M_data); + allocator_type __a = get_allocator(); + __alloc_traits<allocator_type>::destroy(__a, &__node->_M_data); this->_M_put_node(__node); } diff --git a/libstdc++-v3/include/tr1/hashtable.h b/libstdc++-v3/include/tr1/hashtable.h index 354d7b8..e6455eb 100644 --- a/libstdc++-v3/include/tr1/hashtable.h +++ b/libstdc++-v3/include/tr1/hashtable.h @@ -126,6 +126,8 @@ namespace tr1 __constant_iterators, __unique_keys> > { + typedef __gnu_cxx::__alloc_traits<_Allocator> _Alloc_traits; + public: typedef _Allocator allocator_type; typedef _Value value_type; @@ -135,10 +137,10 @@ namespace tr1 // hasher, if present, comes from _Hash_code_base. typedef typename _Allocator::difference_type difference_type; typedef typename _Allocator::size_type size_type; - typedef typename _Allocator::pointer pointer; - typedef typename _Allocator::const_pointer const_pointer; - typedef typename _Allocator::reference reference; - typedef typename _Allocator::const_reference const_reference; + typedef typename _Alloc_traits::pointer pointer; + typedef typename _Alloc_traits::const_pointer const_pointer; + typedef typename _Alloc_traits::reference reference; + typedef typename _Alloc_traits::const_reference const_reference; typedef __detail::_Node_iterator<value_type, __constant_iterators, __cache_hash_code> @@ -162,13 +164,13 @@ namespace tr1 private: typedef __detail::_Hash_node<_Value, __cache_hash_code> _Node; - typedef typename _Allocator::template rebind<_Node>::other - _Node_allocator_type; - typedef typename _Allocator::template rebind<_Node*>::other - _Bucket_allocator_type; + typedef typename _Alloc_traits::template rebind<_Node>::other + _Node_allocator_type; + typedef typename _Alloc_traits::template rebind<_Node*>::other + _Bucket_allocator_type; - typedef typename _Allocator::template rebind<_Value>::other - _Value_allocator_type; + typedef typename _Alloc_traits::template rebind<_Value>::other + _Value_allocator_type; _Node_allocator_type _M_node_allocator; _Node** _M_buckets; @@ -259,7 +261,10 @@ namespace tr1 size_type max_size() const - { return _M_node_allocator.max_size(); } + { + typedef __gnu_cxx::__alloc_traits<_Node_allocator_type> _Traits; + return _Traits::max_size(_M_node_allocator); + } // Observers key_equal diff --git a/libstdc++-v3/include/tr1/regex b/libstdc++-v3/include/tr1/regex index 73c610d..01c85e9 100644 --- a/libstdc++-v3/include/tr1/regex +++ b/libstdc++-v3/include/tr1/regex @@ -1789,7 +1789,7 @@ namespace regex_constants */ //@{ typedef sub_match<_Bi_iter> value_type; - typedef typename _Allocator::const_reference const_reference; + typedef typename _Base_type::const_reference const_reference; typedef const_reference reference; typedef typename _Base_type::const_iterator const_iterator; typedef const_iterator iterator; diff --git a/libstdc++-v3/testsuite/backward/hash_map/23528.cc b/libstdc++-v3/testsuite/backward/hash_map/23528.cc index 01ff4bb..712a65d 100644 --- a/libstdc++-v3/testsuite/backward/hash_map/23528.cc +++ b/libstdc++-v3/testsuite/backward/hash_map/23528.cc @@ -30,9 +30,13 @@ void test01() __gnu_cxx::hash_map<int, int>::value_type *y = a.allocate(1); +#if __cplusplus >= 201103L + std::allocator_traits<decltype(a)>::construct(a, y, *m.begin()); + std::allocator_traits<decltype(a)>::destroy(a, y); +#else a.construct(y, *m.begin()); - a.destroy(y); +#endif a.deallocate(y, 1); } diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered_map/capacity/29134-map.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered_map/capacity/29134-map.cc index 78febb0..0e01c04 100644 --- a/libstdc++-v3/testsuite/tr1/6_containers/unordered_map/capacity/29134-map.cc +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered_map/capacity/29134-map.cc @@ -19,14 +19,16 @@ #include <tr1/unordered_map> #include <testsuite_hooks.h> +#include <testsuite_allocator.h> // libstdc++/29134 void test01() { std::tr1::unordered_map<int, int> um; - VERIFY( (um.max_size() == std::allocator<std::tr1::__detail::_Hash_node< - std::pair<const int, int>, false> >().max_size())); + std::allocator<std::tr1::__detail::_Hash_node<std::pair<const int, int>, + false> > a; + VERIFY( um.max_size() == __gnu_test::max_size(a) ); } int main() diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/capacity/29134-multimap.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/capacity/29134-multimap.cc index 6695fb9..f38c8df 100644 --- a/libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/capacity/29134-multimap.cc +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/capacity/29134-multimap.cc @@ -19,14 +19,16 @@ #include <tr1/unordered_map> #include <testsuite_hooks.h> +#include <testsuite_allocator.h> // libstdc++/29134 void test01() { std::tr1::unordered_multimap<int, int> umm; - VERIFY( (umm.max_size() == std::allocator<std::tr1::__detail::_Hash_node< - std::pair<const int, int>, false> >().max_size()) ); + std::allocator<std::tr1::__detail::_Hash_node<std::pair<const int, int>, + false> > a; + VERIFY( umm.max_size() == __gnu_test::max_size(a) ); } int main() diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered_multiset/capacity/29134-multiset.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered_multiset/capacity/29134-multiset.cc index e9da207..01a2c00 100644 --- a/libstdc++-v3/testsuite/tr1/6_containers/unordered_multiset/capacity/29134-multiset.cc +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered_multiset/capacity/29134-multiset.cc @@ -19,14 +19,15 @@ #include <tr1/unordered_set> #include <testsuite_hooks.h> +#include <testsuite_allocator.h> // libstdc++/29134 void test01() { std::tr1::unordered_multiset<int> ums; - VERIFY( (ums.max_size() == std::allocator<std::tr1::__detail::_Hash_node< - int, false> >().max_size()) ); + std::allocator<std::tr1::__detail::_Hash_node<int, false> > a; + VERIFY( ums.max_size() == __gnu_test::max_size(a) ); } int main() diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered_set/capacity/29134-set.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered_set/capacity/29134-set.cc index 2080aaa..5dd1332 100644 --- a/libstdc++-v3/testsuite/tr1/6_containers/unordered_set/capacity/29134-set.cc +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered_set/capacity/29134-set.cc @@ -19,14 +19,15 @@ #include <tr1/unordered_set> #include <testsuite_hooks.h> +#include <testsuite_allocator.h> // libstdc++/29134 void test01() { std::tr1::unordered_set<int> us; - VERIFY( (us.max_size() == std::allocator<std::tr1::__detail::_Hash_node< - int, false> >().max_size()) ); + std::allocator<std::tr1::__detail::_Hash_node<int, false> > a; + VERIFY( us.max_size() == __gnu_test::max_size(a) ); } int main() |