]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Remove redundant std::allocator members for C++20
authorJonathan Wakely <jwakely@redhat.com>
Tue, 22 Oct 2019 21:48:39 +0000 (22:48 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 22 Oct 2019 21:48:39 +0000 (22:48 +0100)
C++20 removes a number of std::allocator members that have correct
defaults provided by std::allocator_traits, so aren't needed.

Several extensions including __gnu_cxx::hash_map and tr1 containers are
no longer usable with std::allocator in C++20 mode. They need to be
updated to use __gnu_cxx::__alloc_traits in a follow-up patch.

* include/bits/alloc_traits.h
(allocator_traits<allocator<T>>::allocate): Ignore hint for C++20.
(allocator_traits<allocator<T>>::construct): Perform placement new
directly for C++20, instead of calling allocator<T>::construct.
(allocator_traits<allocator<T>>::destroy): Call destructor directly
for C++20, instead of calling allocator<T>::destroy.
(allocator_traits<allocator<T>>::max_size): Return value directly
for C++20, instead of calling std::allocator<T>::max_size().
(__do_alloc_on_copy, __do_alloc_on_move, __do_alloc_on_swap): Do not
define for C++17 and up.
(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use if-constexpr
for C++17 and up, instead of tag dispatching.
* include/bits/allocator.h (allocator<void>): Remove for C++20.
(allocator::pointer, allocator::const_pointer, allocator::reference)
(allocator::const_reference, allocator::rebind): Remove for C++20.
* include/bits/basic_string.h (basic_string): Use __alloc_traits to
rebind allocator.
* include/bits/memoryfwd.h (allocator<void>): Remove for C++20.
* include/ext/debug_allocator.h: Use __alloc_traits for rebinding.
* include/ext/malloc_allocator.h (malloc_allocator::~malloc_allocator)
(malloc_allocator::pointer, malloc_allocator::const_pointer)
(malloc_allocator::reference, malloc_allocator::const_reference)
(malloc_allocator::rebind, malloc_allocator::max_size)
(malloc_allocator::construct, malloc_allocator::destroy): Do not
define for C++20.
(malloc_allocator::_M_max_size): Define new function.
* include/ext/new_allocator.h (new_allocator::~new_allocator)
(new_allocator::pointer, new_allocator::const_pointer)
(new_allocator::reference, new_allocator::const_reference)
(new_allocator::rebind, new_allocator::max_size)
(new_allocator::construct, new_allocator::destroy): Do not
define for C++20.
(new_allocator::_M_max_size): Define new function.
* include/ext/rc_string_base.h (__rc_string_base::_Rep): Use
__alloc_traits to rebind allocator.
* include/ext/rope (_Rope_rep_base, _Rope_base): Likewise.
(rope::rope(CharT, const allocator_type&)): Use __alloc_traits
to construct character.
* include/ext/slist (_Slist_base): Use __alloc_traits to rebind
allocator.
* include/ext/sso_string_base.h (__sso_string_base::_M_max_size):
Use __alloc_traits.
* include/ext/throw_allocator.h (throw_allocator): Do not use optional
members of std::allocator, use __alloc_traits members instead.
* include/ext/vstring.h (__versa_string): Use __alloc_traits.
* include/ext/vstring_util.h (__vstring_utility): Likewise.
* include/std/memory: Include <bits/alloc_traits.h>.
* testsuite/20_util/allocator/8230.cc: Use __gnu_test::max_size.
* testsuite/20_util/allocator/rebind_c++20.cc: New test.
* testsuite/20_util/allocator/requirements/typedefs.cc: Do not check
for pointer, const_pointer, reference, const_reference or rebind in
C++20.
* testsuite/20_util/allocator/requirements/typedefs_c++20.cc: New test.
* testsuite/23_containers/deque/capacity/29134.cc: Use
__gnu_test::max_size.
* testsuite/23_containers/forward_list/capacity/1.cc: Likewise.
* testsuite/23_containers/list/capacity/29134.cc: Likewise.
* testsuite/23_containers/map/capacity/29134.cc: Likewise.
* testsuite/23_containers/multimap/capacity/29134.cc: Likewise.
* testsuite/23_containers/multiset/capacity/29134.cc: Likewise.
* testsuite/23_containers/set/capacity/29134.cc: Likewise.
* testsuite/23_containers/vector/capacity/29134.cc: Likewise.
* testsuite/ext/malloc_allocator/variadic_construct.cc: Do not run
test for C++20.
* testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
* testsuite/ext/vstring/capacity/29134.cc: Use __gnu_test::max_size.
* testsuite/util/replacement_memory_operators.h: Do not assume
Alloc::pointer exists.
* testsuite/util/testsuite_allocator.h (__gnu_test::max_size): Define
helper to call max_size for any allocator.

From-SVN: r277300

33 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/alloc_traits.h
libstdc++-v3/include/bits/allocator.h
libstdc++-v3/include/bits/basic_string.h
libstdc++-v3/include/bits/memoryfwd.h
libstdc++-v3/include/ext/debug_allocator.h
libstdc++-v3/include/ext/malloc_allocator.h
libstdc++-v3/include/ext/new_allocator.h
libstdc++-v3/include/ext/rc_string_base.h
libstdc++-v3/include/ext/rope
libstdc++-v3/include/ext/slist
libstdc++-v3/include/ext/sso_string_base.h
libstdc++-v3/include/ext/throw_allocator.h
libstdc++-v3/include/ext/vstring.h
libstdc++-v3/include/ext/vstring_util.h
libstdc++-v3/include/std/memory
libstdc++-v3/testsuite/20_util/allocator/8230.cc
libstdc++-v3/testsuite/20_util/allocator/rebind_c++20.cc [new file with mode: 0644]
libstdc++-v3/testsuite/20_util/allocator/requirements/typedefs.cc
libstdc++-v3/testsuite/20_util/allocator/requirements/typedefs_c++20.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/deque/capacity/29134.cc
libstdc++-v3/testsuite/23_containers/forward_list/capacity/1.cc
libstdc++-v3/testsuite/23_containers/list/capacity/29134.cc
libstdc++-v3/testsuite/23_containers/map/capacity/29134.cc
libstdc++-v3/testsuite/23_containers/multimap/capacity/29134.cc
libstdc++-v3/testsuite/23_containers/multiset/capacity/29134.cc
libstdc++-v3/testsuite/23_containers/set/capacity/29134.cc
libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc
libstdc++-v3/testsuite/ext/malloc_allocator/variadic_construct.cc
libstdc++-v3/testsuite/ext/new_allocator/variadic_construct.cc
libstdc++-v3/testsuite/ext/vstring/capacity/29134.cc
libstdc++-v3/testsuite/util/replacement_memory_operators.h
libstdc++-v3/testsuite/util/testsuite_allocator.h

index 96a7026060797d5688782caf1b476e8bfa536a20..f5d2a0189e4320e4f0dfd6b1346d85b2ba38d8ad 100644 (file)
@@ -1,3 +1,76 @@
+2019-10-22  Jonathan Wakely  <jwakely@redhat.com>
+
+       * include/bits/alloc_traits.h
+       (allocator_traits<allocator<T>>::allocate): Ignore hint for C++20.
+       (allocator_traits<allocator<T>>::construct): Perform placement new
+       directly for C++20, instead of calling allocator<T>::construct.
+       (allocator_traits<allocator<T>>::destroy): Call destructor directly
+       for C++20, instead of calling allocator<T>::destroy.
+       (allocator_traits<allocator<T>>::max_size): Return value directly
+       for C++20, instead of calling std::allocator<T>::max_size().
+       (__do_alloc_on_copy, __do_alloc_on_move, __do_alloc_on_swap): Do not
+       define for C++17 and up.
+       (__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use if-constexpr
+       for C++17 and up, instead of tag dispatching.
+       * include/bits/allocator.h (allocator<void>): Remove for C++20.
+       (allocator::pointer, allocator::const_pointer, allocator::reference)
+       (allocator::const_reference, allocator::rebind): Remove for C++20.
+       * include/bits/basic_string.h (basic_string): Use __alloc_traits to
+       rebind allocator.
+       * include/bits/memoryfwd.h (allocator<void>): Remove for C++20.
+       * include/ext/debug_allocator.h: Use __alloc_traits for rebinding.
+       * include/ext/malloc_allocator.h (malloc_allocator::~malloc_allocator)
+       (malloc_allocator::pointer, malloc_allocator::const_pointer)
+       (malloc_allocator::reference, malloc_allocator::const_reference)
+       (malloc_allocator::rebind, malloc_allocator::max_size)
+       (malloc_allocator::construct, malloc_allocator::destroy): Do not
+       define for C++20.
+       (malloc_allocator::_M_max_size): Define new function.
+       * include/ext/new_allocator.h (new_allocator::~new_allocator)
+       (new_allocator::pointer, new_allocator::const_pointer)
+       (new_allocator::reference, new_allocator::const_reference)
+       (new_allocator::rebind, new_allocator::max_size)
+       (new_allocator::construct, new_allocator::destroy): Do not
+       define for C++20.
+       (new_allocator::_M_max_size): Define new function.
+       * include/ext/rc_string_base.h (__rc_string_base::_Rep): Use
+       __alloc_traits to rebind allocator.
+       * include/ext/rope (_Rope_rep_base, _Rope_base): Likewise.
+       (rope::rope(CharT, const allocator_type&)): Use __alloc_traits
+       to construct character.
+       * include/ext/slist (_Slist_base): Use __alloc_traits to rebind
+       allocator.
+       * include/ext/sso_string_base.h (__sso_string_base::_M_max_size):
+       Use __alloc_traits.
+       * include/ext/throw_allocator.h (throw_allocator): Do not use optional
+       members of std::allocator, use __alloc_traits members instead.
+       * include/ext/vstring.h (__versa_string): Use __alloc_traits.
+       * include/ext/vstring_util.h (__vstring_utility): Likewise.
+       * include/std/memory: Include <bits/alloc_traits.h>.
+       * testsuite/20_util/allocator/8230.cc: Use __gnu_test::max_size.
+       * testsuite/20_util/allocator/rebind_c++20.cc: New test.
+       * testsuite/20_util/allocator/requirements/typedefs.cc: Do not check
+       for pointer, const_pointer, reference, const_reference or rebind in
+       C++20.
+       * testsuite/20_util/allocator/requirements/typedefs_c++20.cc: New test.
+       * testsuite/23_containers/deque/capacity/29134.cc: Use
+       __gnu_test::max_size.
+       * testsuite/23_containers/forward_list/capacity/1.cc: Likewise.
+       * testsuite/23_containers/list/capacity/29134.cc: Likewise.
+       * testsuite/23_containers/map/capacity/29134.cc: Likewise.
+       * testsuite/23_containers/multimap/capacity/29134.cc: Likewise.
+       * testsuite/23_containers/multiset/capacity/29134.cc: Likewise.
+       * testsuite/23_containers/set/capacity/29134.cc: Likewise.
+       * testsuite/23_containers/vector/capacity/29134.cc: Likewise.
+       * testsuite/ext/malloc_allocator/variadic_construct.cc: Do not run
+       test for C++20.
+       * testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
+       * testsuite/ext/vstring/capacity/29134.cc: Use __gnu_test::max_size.
+       * testsuite/util/replacement_memory_operators.h: Do not assume
+       Alloc::pointer exists.
+       * testsuite/util/testsuite_allocator.h (__gnu_test::max_size): Define
+       helper to call max_size for any allocator.
+
 2019-10-22  Andreas Schwab  <schwab@suse.de>
 
        * config/abi/post/aarch64-linux-gnu/baseline_symbols.txt: Update.
index cda768bf391b12c956582d40cd179978c564356d..62bbf0b2e317bd5f8a899082b9e5b60735974e8f 100644 (file)
@@ -393,6 +393,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       /// The allocator type
       using allocator_type = allocator<_Tp>;
+
       /// The allocated type
       using value_type = _Tp;
 
@@ -455,7 +456,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       */
       _GLIBCXX_NODISCARD static pointer
       allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
-      { return __a.allocate(__n, __hint); }
+      {
+#if __cplusplus <= 201703L
+       return __a.allocate(__n, __hint);
+#else
+       return __a.allocate(__n);
+#endif
+      }
 
       /**
        *  @brief  Deallocate memory.
@@ -480,8 +487,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _Up, typename... _Args>
        static void
        construct(allocator_type& __a, _Up* __p, _Args&&... __args)
-       noexcept(noexcept(__a.construct(__p, std::forward<_Args>(__args)...)))
-       { __a.construct(__p, std::forward<_Args>(__args)...); }
+       noexcept(noexcept(::new((void*)__p) _Up(std::forward<_Args>(__args)...)))
+       {
+#if __cplusplus <= 201703L
+         __a.construct(__p, std::forward<_Args>(__args)...);
+#else
+         ::new((void*)__p) _Up(std::forward<_Args>(__args)...);
+#endif
+       }
 
       /**
        *  @brief  Destroy an object of type @a _Up
@@ -493,8 +506,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       template<typename _Up>
        static void
        destroy(allocator_type& __a, _Up* __p)
-       noexcept(noexcept(__a.destroy(__p)))
-       { __a.destroy(__p); }
+       noexcept(is_nothrow_destructible<_Up>::value)
+       {
+#if __cplusplus <= 201703L
+         __a.destroy(__p);
+#else
+         __p->~_Up();
+#endif
+       }
 
       /**
        *  @brief  The maximum supported allocation size
@@ -503,7 +522,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       */
       static size_type
       max_size(const allocator_type& __a) noexcept
-      { return __a.max_size(); }
+      {
+#if __cplusplus <= 201703L
+       return __a.max_size();
+#else
+       return size_t(-1) / sizeof(value_type);
+#endif
+      }
 
       /**
        *  @brief  Obtain an allocator to use when copying a container.
@@ -515,7 +540,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return __rhs; }
     };
 
-
+#if __cplusplus < 201703L
   template<typename _Alloc>
     inline void
     __do_alloc_on_copy(_Alloc& __one, const _Alloc& __two, true_type)
@@ -525,13 +550,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline void
     __do_alloc_on_copy(_Alloc&, const _Alloc&, false_type)
     { }
+#endif
 
   template<typename _Alloc>
     inline void __alloc_on_copy(_Alloc& __one, const _Alloc& __two)
     {
       typedef allocator_traits<_Alloc> __traits;
       typedef typename __traits::propagate_on_container_copy_assignment __pocca;
+#if __cplusplus >= 201703L
+      if constexpr (__pocca::value)
+       __one = __two;
+#else
       __do_alloc_on_copy(__one, __two, __pocca());
+#endif
     }
 
   template<typename _Alloc>
@@ -541,6 +572,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return __traits::select_on_container_copy_construction(__a);
     }
 
+#if __cplusplus < 201703L
   template<typename _Alloc>
     inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two, true_type)
     { __one = std::move(__two); }
@@ -548,15 +580,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Alloc>
     inline void __do_alloc_on_move(_Alloc&, _Alloc&, false_type)
     { }
+#endif
 
   template<typename _Alloc>
     inline void __alloc_on_move(_Alloc& __one, _Alloc& __two)
     {
       typedef allocator_traits<_Alloc> __traits;
       typedef typename __traits::propagate_on_container_move_assignment __pocma;
+#if __cplusplus >= 201703L
+      if constexpr (__pocma::value)
+       __one = std::move(__two);
+#else
       __do_alloc_on_move(__one, __two, __pocma());
+#endif
     }
 
+#if __cplusplus < 201703L
   template<typename _Alloc>
     inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two, true_type)
     {
@@ -567,13 +606,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Alloc>
     inline void __do_alloc_on_swap(_Alloc&, _Alloc&, false_type)
     { }
+#endif
 
   template<typename _Alloc>
     inline void __alloc_on_swap(_Alloc& __one, _Alloc& __two)
     {
       typedef allocator_traits<_Alloc> __traits;
       typedef typename __traits::propagate_on_container_swap __pocs;
+#if __cplusplus >= 201703L
+      if constexpr (__pocs::value)
+       {
+         using std::swap;
+         swap(__one, __two);
+       }
+#else
       __do_alloc_on_swap(__one, __two, __pocs());
+#endif
     }
 
   template<typename _Alloc, typename _Tp,
index f0f8fe41e31e11e26b7c89b020ced89621212312..62a40a17e3c6879591731805d8ce06a2f32af736 100644 (file)
@@ -63,6 +63,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    *  @{
    */
 
+#if __cplusplus <= 201703L
   /// allocator<void> specialization.
   template<>
     class allocator<void>
@@ -97,8 +98,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        destroy(_Up* __p)
        noexcept(noexcept(__p->~_Up()))
        { __p->~_Up(); }
-#endif
+#endif // C++11
     };
+#endif // ! C++20
 
   /**
    * @brief  The @a standard allocator, as per [20.4].
@@ -111,18 +113,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Tp>
     class allocator : public __allocator_base<_Tp>
     {
-   public:
+    public:
+      typedef _Tp        value_type;
       typedef size_t     size_type;
       typedef ptrdiff_t  difference_type;
+#if __cplusplus <= 201703L
       typedef _Tp*       pointer;
       typedef const _Tp* const_pointer;
       typedef _Tp&       reference;
       typedef const _Tp& const_reference;
-      typedef _Tp        value_type;
 
       template<typename _Tp1>
        struct rebind
        { typedef allocator<_Tp1> other; };
+#endif
 
 #if __cplusplus >= 201103L
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
index f1bdc6c553ff0a983542735d3a4520a750a24bc7..37e75b455d33cfb5437cb49c039bbbe19418bd75 100644 (file)
@@ -3138,7 +3138,9 @@ _GLIBCXX_END_NAMESPACE_CXX11
   template<typename _CharT, typename _Traits, typename _Alloc>
     class basic_string
     {
-      typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
+      typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
+       rebind<_CharT>::other _CharT_alloc_type;
+      typedef __gnu_cxx::__alloc_traits<_CharT_alloc_type> _CharT_alloc_traits;
 
       // Types:
     public:
@@ -3154,8 +3156,8 @@ _GLIBCXX_END_NAMESPACE_CXX11
       typedef value_type&                                  reference;
       typedef const value_type&                                    const_reference;
 #endif
-      typedef typename _CharT_alloc_type::pointer          pointer;
-      typedef typename _CharT_alloc_type::const_pointer            const_pointer;
+      typedef typename _CharT_alloc_traits::pointer        pointer;
+      typedef typename _CharT_alloc_traits::const_pointer   const_pointer;
       typedef __gnu_cxx::__normal_iterator<pointer, basic_string>  iterator;
       typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
                                                             const_iterator;
@@ -3191,7 +3193,8 @@ _GLIBCXX_END_NAMESPACE_CXX11
       struct _Rep : _Rep_base
       {
        // Types:
-       typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
+       typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
+         rebind<char>::other _Raw_bytes_alloc;
 
        // (Public) Data members:
 
index 8b1664a398d55b7fa53d2bce68953d84826f1a40..d42eabeceb898b0aacc3f452202bc2070de51477 100644 (file)
@@ -63,8 +63,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename>
     class allocator;
 
+#if __cplusplus <= 201703L
   template<>
     class allocator<void>;
+#endif
 
   /// Declare uses_allocator so it can be specialized in \<queue\> etc.
   template<typename, typename>
index 08f0eb23f5b1681801c733d45f04aa2edde72ea8..b8e0e64d7bda607c9091964ce5d7cc94ba82d444 100644 (file)
@@ -89,7 +89,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _Alloc                   _M_allocator;
 
       template<typename _Alloc2,
-              typename = typename _Alloc2::template rebind<value_type>::other>
+              typename = typename __alloc_traits<_Alloc2>::template
+                          rebind<value_type>::other>
        struct __convertible
        { };
 
index 1bc76372f4468523a22c0938c3d5a668c3eeab38..cf6284080e8df7d969d432cba26b5b85bf5e7189 100644 (file)
@@ -54,17 +54,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     class malloc_allocator
     {
     public:
+      typedef _Tp        value_type;
       typedef std::size_t     size_type;
       typedef std::ptrdiff_t  difference_type;
+#if __cplusplus <= 201703L
       typedef _Tp*       pointer;
       typedef const _Tp* const_pointer;
       typedef _Tp&       reference;
       typedef const _Tp& const_reference;
-      typedef _Tp        value_type;
 
       template<typename _Tp1>
         struct rebind
         { typedef malloc_allocator<_Tp1> other; };
+#endif
 
 #if __cplusplus >= 201103L
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
@@ -83,6 +85,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
         malloc_allocator(const malloc_allocator<_Tp1>&)
        _GLIBCXX_USE_NOEXCEPT { }
 
+#if __cplusplus <= 201703L
       ~malloc_allocator() _GLIBCXX_USE_NOEXCEPT { }
 
       pointer
@@ -92,16 +95,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       const_pointer
       address(const_reference __x) const _GLIBCXX_NOEXCEPT
       { return std::__addressof(__x); }
+#endif
 
       // NB: __n is permitted to be 0.  The C++ standard says nothing
       // about what the return value is when __n == 0.
-      pointer
+      _Tp*
       allocate(size_type __n, const void* = 0)
       {
-       if (__n > this->max_size())
+       if (__n > this->_M_max_size())
          std::__throw_bad_alloc();
 
-       pointer __ret = 0;
+       _Tp* __ret = 0;
 #if __cpp_aligned_new
 #if __cplusplus > 201402L && _GLIBCXX_HAVE_ALIGNED_ALLOC
        if (alignof(_Tp) > alignof(std::max_align_t))
@@ -131,18 +135,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       // __p is not permitted to be a null pointer.
       void
-      deallocate(pointer __p, size_type)
+      deallocate(_Tp* __p, size_type)
       { std::free(static_cast<void*>(__p)); }
 
+#if __cplusplus <= 201703L
       size_type
       max_size() const _GLIBCXX_USE_NOEXCEPT 
-      {
-#if __PTRDIFF_MAX__ < __SIZE_MAX__
-       return std::size_t(__PTRDIFF_MAX__) / sizeof(_Tp);
-#else
-       return std::size_t(-1) / sizeof(_Tp);
-#endif
-      }
+      { return _M_max_size(); }
 
 #if __cplusplus >= 201103L
       template<typename _Up, typename... _Args>
@@ -160,13 +159,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #else
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 402. wrong new expression in [some_] allocator::construct
-      void 
-      construct(pointer __p, const _Tp& __val) 
+      void
+      construct(pointer __p, const _Tp& __val)
       { ::new((void *)__p) value_type(__val); }
 
-      void 
+      void
       destroy(pointer __p) { __p->~_Tp(); }
 #endif
+#endif // ! C++20
 
       template<typename _Up>
        friend bool
@@ -179,6 +179,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        operator!=(const malloc_allocator&, const malloc_allocator<_Up>&)
        _GLIBCXX_NOTHROW
        { return false; }
+
+    private:
+      _GLIBCXX_CONSTEXPR size_type
+      _M_max_size() const _GLIBCXX_USE_NOEXCEPT
+      {
+#if __PTRDIFF_MAX__ < __SIZE_MAX__
+       return std::size_t(__PTRDIFF_MAX__) / sizeof(_Tp);
+#else
+       return std::size_t(-1) / sizeof(_Tp);
+#endif
+      }
     };
 
 _GLIBCXX_END_NAMESPACE_VERSION
index ee699532c6a2bc32bef827a9ecccbea15edfe579..cff9f1dca9c507746d50409947591dc93f93e6e1 100644 (file)
@@ -55,17 +55,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     class new_allocator
     {
     public:
+      typedef _Tp        value_type;
       typedef std::size_t     size_type;
       typedef std::ptrdiff_t  difference_type;
+#if __cplusplus <= 201703L
       typedef _Tp*       pointer;
       typedef const _Tp* const_pointer;
       typedef _Tp&       reference;
       typedef const _Tp& const_reference;
-      typedef _Tp        value_type;
 
       template<typename _Tp1>
        struct rebind
        { typedef new_allocator<_Tp1> other; };
+#endif
 
 #if __cplusplus >= 201103L
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
@@ -83,6 +85,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        _GLIBCXX20_CONSTEXPR
        new_allocator(const new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { }
 
+#if __cplusplus <= 201703L
       ~new_allocator() _GLIBCXX_USE_NOEXCEPT { }
 
       pointer
@@ -92,13 +95,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       const_pointer
       address(const_reference __x) const _GLIBCXX_NOEXCEPT
       { return std::__addressof(__x); }
+#endif
 
       // NB: __n is permitted to be 0.  The C++ standard says nothing
       // about what the return value is when __n == 0.
-      _GLIBCXX_NODISCARD pointer
+      _GLIBCXX_NODISCARD _Tp*
       allocate(size_type __n, const void* = static_cast<const void*>(0))
       {
-       if (__n > this->max_size())
+       if (__n > this->_M_max_size())
          std::__throw_bad_alloc();
 
 #if __cpp_aligned_new
@@ -113,7 +117,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       // __p is not permitted to be a null pointer.
       void
-      deallocate(pointer __p, size_type __t)
+      deallocate(_Tp* __p, size_type __t)
       {
 #if __cpp_aligned_new
        if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
@@ -133,15 +137,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                         );
       }
 
+#if __cplusplus <= 201703L
       size_type
       max_size() const _GLIBCXX_USE_NOEXCEPT
-      {
-#if __PTRDIFF_MAX__ < __SIZE_MAX__
-       return std::size_t(__PTRDIFF_MAX__) / sizeof(_Tp);
-#else
-       return std::size_t(-1) / sizeof(_Tp);
-#endif
-      }
+      { return _M_max_size(); }
 
 #if __cplusplus >= 201103L
       template<typename _Up, typename... _Args>
@@ -166,6 +165,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       void
       destroy(pointer __p) { __p->~_Tp(); }
 #endif
+#endif // ! C++20
 
       template<typename _Up>
        friend bool
@@ -178,6 +178,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        operator!=(const new_allocator&, const new_allocator<_Up>&)
        _GLIBCXX_NOTHROW
        { return false; }
+
+    private:
+      _GLIBCXX_CONSTEXPR size_type
+      _M_max_size() const _GLIBCXX_USE_NOEXCEPT
+      {
+#if __PTRDIFF_MAX__ < __SIZE_MAX__
+       return std::size_t(__PTRDIFF_MAX__) / sizeof(_Tp);
+#else
+       return std::size_t(-1) / sizeof(_Tp);
+#endif
+      }
     };
 
 _GLIBCXX_END_NAMESPACE_VERSION
index 529035c5f61a13068fd990197dabef5c0ca31fa0..2cf5fb0c5e3d14d21b19e62c3027d0944feb21f0 100644 (file)
@@ -31,6 +31,7 @@
 #define _RC_STRING_BASE_H 1
 
 #include <ext/atomicity.h>
+#include <ext/alloc_traits.h>
 #include <bits/stl_iterator_base_funcs.h>
 
 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
@@ -120,7 +121,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          _CharT            _M_align;
        };
 
-       typedef typename _Alloc::template rebind<_Rep>::other _Rep_alloc_type;
+       typedef typename __alloc_traits<_Alloc>::template rebind<_Rep>::other
+         _Rep_alloc_type;
 
        _CharT*
        _M_refdata() throw()
index 0788dee3c71a8ac3a5c83a08ce5f0276cd94e9be..bfb29e1852d1b8aa053501e296d276094f7907a1 100644 (file)
@@ -53,6 +53,7 @@
 #include <bits/stl_numeric.h>
 #include <bits/allocator.h>
 #include <bits/gthr.h>
+#include <ext/alloc_traits.h>
 #include <tr1/functional>
 
 # ifdef __GC
@@ -565,7 +566,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 # define __ROPE_DEFINE_ALLOC(_Tp, __name) \
         typedef typename \
-          _Alloc::template rebind<_Tp>::other __name##Alloc; \
+          __alloc_traits<_Alloc>::template rebind<_Tp>::other __name##Alloc; \
         static _Tp* __name##_allocate(size_type __n) \
           { return __name##Alloc().allocate(__n); } \
         static void __name##_deallocate(_Tp *__p, size_type __n) \
@@ -1499,7 +1500,7 @@ protected:
 
 #define __ROPE_DEFINE_ALLOC(_Tp, __name) \
         typedef typename \
-          _Alloc::template rebind<_Tp>::other __name##Alloc; \
+          __alloc_traits<_Alloc>::template rebind<_Tp>::other __name##Alloc; \
         static _Tp* __name##_allocate(std::size_t __n) \
           { return __name##Alloc().allocate(__n); } \
         static void __name##_deallocate(_Tp *__p, std::size_t __n) \
@@ -1855,7 +1856,8 @@ protected:
       {
        _CharT* __buf = this->_Data_allocate(_S_rounded_up_size(1));
        
-       _M_get_allocator().construct(__buf, __c);
+       __alloc_traits<allocator_type>::construct(_M_get_allocator(),
+                                                 __buf, __c);
        __try
          {
            this->_M_tree_ptr = _S_new_RopeLeaf(__buf, 1,
index ff2ea150c4ac4553e4c411ac4ebd4c6f4b96bcf3..93522caf1f6fe17793b2eb72ff60a5f9c04ab99c 100644 (file)
@@ -217,10 +217,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   template <class _Tp, class _Alloc>
     struct _Slist_base
-    : public _Alloc::template rebind<_Slist_node<_Tp> >::other
+    : public __alloc_traits<_Alloc>::template rebind<_Slist_node<_Tp> >::other
     {
-      typedef typename _Alloc::template rebind<_Slist_node<_Tp> >::other
-        _Node_alloc;
+      typedef typename __alloc_traits<_Alloc>::template
+       rebind<_Slist_node<_Tp> >::other _Node_alloc;
       typedef _Alloc allocator_type;
 
       allocator_type
index beae593efa04578632f7d0b4eff9a42ac8547506..e86d81011dd8094c2dd97eac30a4e2c5de9c1a7f 100644 (file)
@@ -140,7 +140,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     public:
       size_type
       _M_max_size() const
-      { return (_M_get_allocator().max_size() - 1) / 2; }
+      {
+       typedef __alloc_traits<_CharT_alloc_type> _ATraits;
+       return (_ATraits::max_size(_M_get_allocator()) - 1) / 2;
+      }
 
       _CharT*
       _M_data() const
index 38e80f721da80d47eb2c2619daa2b9f5409b88e2..f5da751eb69b129734595b72492e6318bace1020 100644 (file)
@@ -62,6 +62,7 @@
 # include <tr1/functional>
 # include <tr1/random>
 #endif
+#include <ext/alloc_traits.h>
 
 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
 {
@@ -814,12 +815,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
       std::allocator<value_type>               _M_allocator;
 
+      typedef __gnu_cxx::__alloc_traits<std::allocator<value_type> > traits;
+
       using condition_type::throw_conditionally;
 
     public:
       size_type
       max_size() const _GLIBCXX_USE_NOEXCEPT
-      { return _M_allocator.max_size(); }
+      { return traits::max_size(_M_allocator); }
 
       pointer
       address(reference __x) const _GLIBCXX_NOEXCEPT
@@ -830,13 +833,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return std::__addressof(__x); }
 
       _GLIBCXX_NODISCARD pointer
-      allocate(size_type __n, std::allocator<void>::const_pointer hint = 0)
+      allocate(size_type __n, const void* hint = 0)
       {
        if (__n > this->max_size())
          std::__throw_bad_alloc();
 
        throw_conditionally();
-       pointer const a = _M_allocator.allocate(__n, hint);
+       pointer const a = traits::allocate(_M_allocator, __n, hint);
        insert(a, sizeof(value_type) * __n);
        return a;
       }
@@ -846,7 +849,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
         void
         construct(_Up* __p, _Args&&... __args)
        {
-         _M_allocator.construct(__p, std::forward<_Args>(__args)...);
+         traits::construct(_M_allocator, __p, std::forward<_Args>(__args)...);
          insert_construct(__p);
        }
 
@@ -855,7 +858,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
         destroy(_Up* __p)
         {
          erase_construct(__p);
-         _M_allocator.destroy(__p);
+         traits::destroy(_M_allocator, __p);
        }
 #else
       void
index 5942218531f4c904fda66cd640daa3a21fe3f7a5..23ccf15de5b313ab4ffb6b8fa94f0712b976116c 100644 (file)
@@ -58,6 +58,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       typedef _Base<_CharT, _Traits, _Alloc>                __vstring_base;    
       typedef typename __vstring_base::_CharT_alloc_type    _CharT_alloc_type;
+      typedef __alloc_traits<_CharT_alloc_type> _CharT_alloc_traits;
 
       // Types:
     public:
@@ -68,8 +69,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       typedef typename _CharT_alloc_type::difference_type   difference_type;
       typedef value_type&                                  reference;
       typedef const value_type&                             const_reference;
-      typedef typename _CharT_alloc_type::pointer          pointer;
-      typedef typename _CharT_alloc_type::const_pointer            const_pointer;
+      typedef typename _CharT_alloc_traits::pointer        pointer;
+      typedef typename _CharT_alloc_traits::const_pointer   const_pointer;
       typedef __gnu_cxx::__normal_iterator<pointer, __versa_string>  iterator;
       typedef __gnu_cxx::__normal_iterator<const_pointer, __versa_string>
                                                             const_iterator;
index 5d00b165cbe3fca74e28e9442ae1debab4c95408..f539a6b0f2ceff0e9895b6e556bb9f2413b78875 100644 (file)
@@ -40,6 +40,7 @@
 #include <bits/ostream_insert.h>
 #include <bits/stl_iterator.h>
 #include <ext/numeric_traits.h>
+#include <ext/alloc_traits.h>
 #include <bits/move.h>
 #include <bits/range_access.h>
 
@@ -50,14 +51,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _CharT, typename _Traits, typename _Alloc>
     struct __vstring_utility
     {
-      typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
+      typedef typename __alloc_traits<_Alloc>::template rebind<_CharT>::other
+       _CharT_alloc_type;
+      typedef __alloc_traits<_CharT_alloc_type> _CharT_alloc_traits;
 
       typedef _Traits                                      traits_type;
       typedef typename _Traits::char_type                  value_type;
       typedef typename _CharT_alloc_type::size_type        size_type;
       typedef typename _CharT_alloc_type::difference_type   difference_type;
-      typedef typename _CharT_alloc_type::pointer          pointer;
-      typedef typename _CharT_alloc_type::const_pointer            const_pointer;
+      typedef typename _CharT_alloc_traits::pointer        pointer;
+      typedef typename _CharT_alloc_traits::const_pointer   const_pointer;
 
       // For __sso_string.
       typedef __gnu_cxx::
index 0a483d2d8d1a1287685cb5cc8a7d338a14e7fef3..4f09b8deb2c762d400c59f3dfdf96871973b9e0d 100644 (file)
@@ -76,6 +76,7 @@
 #  include <bits/functexcept.h>
 #  include <bits/stl_function.h>  // std::less
 #  include <bits/uses_allocator.h>
+#  include <bits/alloc_traits.h>
 #  include <type_traits>
 #  include <debug/debug.h>
 #  include <bits/unique_ptr.h>
index 917e64de374cb3a4f36a839b3b6755433858dd49..2559a5117fbdd5d06e6bd495e257de4bfd13b895 100644 (file)
@@ -22,6 +22,7 @@
 #include <memory>
 #include <stdexcept>
 #include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
 
 // libstdc++/8230
 void test02()
@@ -30,11 +31,11 @@ void test02()
   try 
     {
       std::allocator<int> alloc;
-      const std::allocator<int>::size_type n = alloc.max_size();
+      const std::allocator<int>::size_type n = __gnu_test::max_size(alloc);
       int* p = alloc.allocate(n + 1);
       p[n] = 2002;
     } 
-  catch(const std::bad_alloc& e) 
+  catch(const std::bad_alloc& e)
     {
       // Allowed.
       test = true;
diff --git a/libstdc++-v3/testsuite/20_util/allocator/rebind_c++20.cc b/libstdc++-v3/testsuite/20_util/allocator/rebind_c++20.cc
new file mode 100644 (file)
index 0000000..968e1de
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <memory>
+
+template<typename T> struct Alloc : std::allocator<T> { };
+
+using T = std::allocator_traits<Alloc<int>>;
+
+// Prior to C++20 this finds std::allocator<int>::rebind and so fails:
+static_assert( std::is_same_v<T::rebind_alloc<long>, Alloc<long>> );
index d293e6b06b69dcbd8c3a1cd73c3d6722895e0ed3..3275164f1441b31a34d2299c9821f2af49924b6d 100644 (file)
@@ -30,6 +30,7 @@ static_assert( is_same<allocator<int>::size_type, std::size_t>::value,
                "size_type" );
 static_assert( is_same<allocator<int>::difference_type, std::ptrdiff_t>::value,
                "difference_type" );
+#if __cplusplus <= 201703L
 static_assert( is_same<allocator<int>::pointer, int*>::value,
                "pointer" );
 static_assert( is_same<allocator<int>::const_pointer, const int*>::value,
@@ -38,12 +39,15 @@ static_assert( is_same<allocator<int>::reference, int&>::value,
                "reference" );
 static_assert( is_same<allocator<int>::const_reference, const int&>::value,
                "const_reference" );
+#endif
 static_assert( is_same<allocator<int>::value_type, int>::value,
                "value_type" );
 
+#if __cplusplus <= 201703L
 static_assert( is_same<allocator<int>::rebind<char>::other,
                        allocator<char>>::value,
                "rebind::other" );
+#endif
 
 static_assert( is_same<allocator<int>::propagate_on_container_move_assignment,
                        std::true_type>::value,
diff --git a/libstdc++-v3/testsuite/20_util/allocator/requirements/typedefs_c++20.cc b/libstdc++-v3/testsuite/20_util/allocator/requirements/typedefs_c++20.cc
new file mode 100644 (file)
index 0000000..e986cc9
--- /dev/null
@@ -0,0 +1,56 @@
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <memory>
+
+template<typename Alloc>
+  concept has_pointer = requires { typename Alloc::pointer; };
+
+template<typename Alloc>
+  concept has_const_pointer = requires { typename Alloc::const_pointer; };
+
+template<typename Alloc>
+  concept has_reference = requires { typename Alloc::reference; };
+
+template<typename Alloc>
+  concept has_const_reference = requires { typename Alloc::const_reference; };
+
+template<typename Alloc>
+  concept has_rebind = requires { typename Alloc::template rebind<long>; };
+
+template<typename Alloc>
+  concept has_construct = requires(Alloc& a, int* p) { a.construct(p); };
+
+template<typename Alloc>
+  concept has_destroy = requires(Alloc& a, int* p) { a.destroy(p); };
+
+template<typename Alloc>
+  concept has_max_size = requires(Alloc& a) { a.max_size(); };
+
+using A = std::allocator<int>;
+
+static_assert( !has_pointer<A> );
+static_assert( !has_const_pointer<A> );
+static_assert( !has_reference<A> );
+static_assert( !has_const_reference<A> );
+static_assert( !has_rebind<A> );
+static_assert( !has_construct<A> );
+static_assert( !has_destroy<A> );
+static_assert( !has_max_size<A> );
index da5ba3575f4ec225be89bf9148a9e5b1e6a851a8..2d6e13d8944838aef7c9abd5eff8d713e4a144e9 100644 (file)
 
 #include <deque>
 #include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
 
 // libstdc++/29134
 void test01()
 {
   std::deque<int> d;
 
-  VERIFY( d.max_size() == d.get_allocator().max_size() );
+  std::allocator<int> a = d.get_allocator();
+  VERIFY( d.max_size() == __gnu_test::max_size(a) );
 }
 
 int main()
index deb71f2d51bea144e9dc0378d7cd0290ba06ce62..b36fdc81ad53ff06012a8050e120a5d8db155236 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <forward_list>
 #include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
 
 void
 test01()
@@ -40,8 +41,8 @@ test01()
   using std::_Fwd_list_node;
 #endif
 
-  VERIFY( (fld.max_size()
-          == std::allocator<_Fwd_list_node<double> >().max_size()) );
+  std::allocator<_Fwd_list_node<double> > a;
+  VERIFY( fld.max_size() == __gnu_test::max_size(a) );
 }
 
 int
index 1b23938c088714f2e9828af8d43b50bd2ad338a4..810d964d28a72f8d35621927cf2e56a73e2114ba 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <list>
 #include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
 
 // libstdc++/29134
 void test01()
@@ -32,7 +33,8 @@ void test01()
   using std::_List_node;
 #endif
 
-  VERIFY( l.max_size() == std::allocator<_List_node<int> >().max_size() );
+  std::allocator<_List_node<int> > a;
+  VERIFY( l.max_size() == __gnu_test::max_size(a) );
 }
 
 int main()
index c1696ba93b470e7441fde21b97b6b371178010d6..eae36f7037bc323510444cf8e41bc721634259e8 100644 (file)
 
 #include <map>
 #include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
 
 // libstdc++/29134
 void test01()
 {
   std::map<int, int> m;
 
-  VERIFY( (m.max_size() == std::allocator<std::_Rb_tree_node<
-                          std::pair<const int, int> > >().max_size()) );
+  std::allocator<std::_Rb_tree_node<std::pair<const int, int> > > a;
+  VERIFY( m.max_size() == __gnu_test::max_size(a) );
 }
 
 int main()
index 52ab07c50b50df279c44b3b9db0cbc29d8e69ffb..ac588de73f7545d194db9c4ac0599f1b725de202 100644 (file)
 
 #include <map>
 #include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
 
 // libstdc++/29134
 void test01()
 {
   std::multimap<int, int> mm;
 
-  VERIFY( (mm.max_size() == std::allocator<std::_Rb_tree_node<
-                           std::pair<const int, int> > >().max_size()) );
+  std::allocator<std::_Rb_tree_node<std::pair<const int, int> > > a;
+  VERIFY( mm.max_size() == __gnu_test::max_size(a) );
 }
 
 int main()
index 7f22a317b73a60311d7f309ff1e0b40bf8006f9b..ea856a55156ec7436887dcf0b27d140b69b027c9 100644 (file)
 
 #include <set>
 #include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
 
 // libstdc++/29134
 void test01()
 {
   std::multiset<int> ms;
 
-  VERIFY( ms.max_size()
-         == std::allocator<std::_Rb_tree_node<int> >().max_size() );
+  std::allocator<std::_Rb_tree_node<int> > a;
+  VERIFY( ms.max_size() == __gnu_test::max_size(a) );
 }
 
 int main()
index f870efda7271a781f2f1aef2e77141a3a3b711ce..7851ee6b7ff0ab1f7ab8125699a5cb98d4b8653f 100644 (file)
 
 #include <set>
 #include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
 
 // libstdc++/29134
 void test01()
 {
   std::set<int> s;
 
-  VERIFY( s.max_size() ==
-         std::allocator<std::_Rb_tree_node<int> >().max_size() );
+  std::allocator<std::_Rb_tree_node<int> > a;
+  VERIFY( s.max_size() == __gnu_test::max_size(a) );
 }
 
 int main()
index 777e1c86238fb64fc2a392b68b49acc64b1fdd89..3d3b60138d0ed2c8fd13fd2c9cc5faafc6e0f8c3 100644 (file)
 
 #include <vector>
 #include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
 
 // libstdc++/29134
 void test01()
 {
   std::vector<int> v;
 
-  VERIFY( v.max_size() == v.get_allocator().max_size() );
+  std::allocator<int> a = v.get_allocator();
+#if __cplusplus > 201703L
+  // std::allocator_traits::max_size() is unrealistically large,
+  // so std::vector::max_size() returns a smaller value.
+  VERIFY( v.max_size() <= __gnu_test::max_size(a) );
+#else
+  VERIFY( v.max_size() == __gnu_test::max_size(a) );
+#endif
+
 }
 
 int main()
index 135c7080fad83f9b4dbc820b7cb907e3aeb04101..b786fae9f0acd27e4f1b4202a82de1fa1a3cb2cd 100644 (file)
@@ -1,4 +1,4 @@
-// { dg-do run { target c++11 } }
+// { dg-do run { target { { c++11_only || c++14_only } || c++17_only } } }
 
 // 2007-10-26  Paolo Carlini  <pcarlini@suse.de>
 
index fe4502f49d6e1485c4f48c72ecdaf3a09d060b18..5b23e5b4a2c07abf4279021963ffd606515cdec6 100644 (file)
@@ -1,4 +1,4 @@
-// { dg-do run { target c++11 } }
+// { dg-do run { target { { c++11_only || c++14_only } || c++17_only } } }
 
 // 2007-10-26  Paolo Carlini  <pcarlini@suse.de>
 
index cc0302b92acd1e877e4095bb576f649de1092da2..003d0406d0a7a9779bbb011d559f4ebd87251c13 100644 (file)
 
 #include <ext/vstring.h>
 #include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
 
 // libstdc++/29134
 void test01()
 {
   __gnu_cxx::__vstring vs;
 
-  VERIFY( vs.max_size() <= vs.get_allocator().max_size() );
+  VERIFY( vs.max_size() <= __gnu_test::max_size(vs.get_allocator()) );
 }
 
 int main()
index fb0b2be7dcf6b61e911331e6fc022790a6f650a8..cb7e7b9027bde6f5d5426101d18d94aa74f46657 100644 (file)
@@ -76,7 +76,11 @@ namespace __gnu_test
     check_delete(Alloc a = Alloc())
     {
       __gnu_test::counter::exceptions(false);
+#if __cplusplus >= 201103L
+      auto p = a.allocate(10);
+#else
       typename Alloc::pointer p = a.allocate(10);
+#endif
       const std::size_t count1 = __gnu_test::counter::count();
       a.deallocate(p, 10);
       const std::size_t count2 = __gnu_test::counter::count();
index 67e70a29edb483af91f28f7eff8f83c099fff6ef..f3eb199d85e97d3bc69cbead829e2fd3b177b01b 100644 (file)
@@ -45,6 +45,18 @@ namespace unord = std::tr1;
 
 namespace __gnu_test
 {
+  // A common API for calling max_size() on an allocator in any -std mode.
+  template<typename A>
+    typename A::size_type
+    max_size(const A& a)
+    {
+#if __cplusplus >= 201103L
+      return std::allocator_traits<A>::max_size(a);
+#else
+      return a.max_size();
+#endif
+    }
+
   class tracker_allocator_counter
   {
   public:
@@ -252,7 +264,7 @@ namespace __gnu_test
       Alloc a;
       try
        {
-         (void) a.allocate(a.max_size() + 1);
+         (void) a.allocate(__gnu_test::max_size(a) + 1);
        }
       catch(std::bad_alloc&)
        {