Adjust extension types to use allocator_traits
authorJonathan Wakely <jwakely@redhat.com>
Wed, 23 Oct 2019 16:14:28 +0000 (17:14 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 23 Oct 2019 16:14:28 +0000 (17:14 +0100)
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

13 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/backward/hash_set
libstdc++-v3/include/backward/hashtable.h
libstdc++-v3/include/ext/alloc_traits.h
libstdc++-v3/include/ext/extptr_allocator.h
libstdc++-v3/include/ext/slist
libstdc++-v3/include/tr1/hashtable.h
libstdc++-v3/include/tr1/regex
libstdc++-v3/testsuite/backward/hash_map/23528.cc
libstdc++-v3/testsuite/tr1/6_containers/unordered_map/capacity/29134-map.cc
libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/capacity/29134-multimap.cc
libstdc++-v3/testsuite/tr1/6_containers/unordered_multiset/capacity/29134-multiset.cc
libstdc++-v3/testsuite/tr1/6_containers/unordered_set/capacity/29134-set.cc

index 87ee636ceb873fcf03c2406284d1a19772c1c6d9..9f19e4f83196dd2b8d4e0b9b08d29ba4bc86d2df 100644 (file)
@@ -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
index 1445aa61e1129b8b2eddaf4a7dd607bee697d6e2..7f743fdf3afeb5ba79077d3bfa428fa2d5bbcd66 100644 (file)
@@ -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;
index df6ad85191c03310002fec49cfd2bfa9919a65c2..cfb9cf957d24c702d107698e6b46531ba7da4962 100644 (file)
@@ -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);
       }
       
index 65fa3de271c87a3aaffc999b50de65dac8e1fef2..65340eb7acc33996904502e38dbf41dfeca41c56 100644 (file)
@@ -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); }
 
index 2ce87b60c44c5bb9a1727d814179e322899bbfe7..4e86fef81e4ad58ba4084721050664d16e612e81 100644 (file)
@@ -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); }
index 93522caf1f6fe17793b2eb72ff60a5f9c04ab99c..cbdfae0bd909915cfe1f37694669f8430c7a6dd3 100644 (file)
@@ -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);
       }
 
index 354d7b814ebab0798044179bffd1cbf4472d8093..e6455ebc3f264e8850f6966b012dc01d0ba78a7c 100644 (file)
@@ -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
index 73c610d2bbdb1a67341948fd7807715c611e0037..01c85e996239f3cc2346eeca1af47b1c28c05506 100644 (file)
@@ -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;
index 01ff4bb42b2a3930cb571c6330c44d7eb5c2d151..712a65d11b938b6e2db42231af8de640ad7c82bf 100644 (file)
@@ -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);
 }
 
index 78febb07e0660b65bf54c3c20727d792431eb6ae..0e01c0411fb586642353b2ecc3b069a5864f7e5a 100644 (file)
 
 #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()
index 6695fb9c5d4cb6a3da44942bb77ac159da0a89f8..f38c8df5c26e5c787989ee44508f07b9cef14cb8 100644 (file)
 
 #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()
index e9da207f1febc2e0236daf45d479e4366ac9ce44..01a2c00c18b466a316ace72f27b4cebccea398dd 100644 (file)
 
 #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()
index 2080aaac01e511c039d61a77615f0068b89e7af1..5dd133265ea1dd88c095febd1a40463b16d43ad5 100644 (file)
 
 #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()