diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2019-10-22 22:48:39 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-10-22 22:48:39 +0100 |
commit | 2cae56bd61a048b0fac5c2829283744abc44c545 (patch) | |
tree | e00cedcecf5fb643b0da4dbfa293969aaee8815e /libstdc++-v3/include/ext | |
parent | 51940760d7158aeb8d6747c9ee0b784d6869c7ef (diff) | |
download | gcc-2cae56bd61a048b0fac5c2829283744abc44c545.zip gcc-2cae56bd61a048b0fac5c2829283744abc44c545.tar.gz gcc-2cae56bd61a048b0fac5c2829283744abc44c545.tar.bz2 |
Remove redundant std::allocator members for C++20
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
Diffstat (limited to 'libstdc++-v3/include/ext')
-rw-r--r-- | libstdc++-v3/include/ext/debug_allocator.h | 3 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/malloc_allocator.h | 41 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/new_allocator.h | 33 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/rc_string_base.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/rope | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/slist | 6 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/sso_string_base.h | 5 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/throw_allocator.h | 13 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/vstring.h | 5 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/vstring_util.h | 9 |
10 files changed, 82 insertions, 45 deletions
diff --git a/libstdc++-v3/include/ext/debug_allocator.h b/libstdc++-v3/include/ext/debug_allocator.h index 08f0eb2..b8e0e64 100644 --- a/libstdc++-v3/include/ext/debug_allocator.h +++ b/libstdc++-v3/include/ext/debug_allocator.h @@ -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 { }; diff --git a/libstdc++-v3/include/ext/malloc_allocator.h b/libstdc++-v3/include/ext/malloc_allocator.h index 1bc7637..cf62840 100644 --- a/libstdc++-v3/include/ext/malloc_allocator.h +++ b/libstdc++-v3/include/ext/malloc_allocator.h @@ -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 diff --git a/libstdc++-v3/include/ext/new_allocator.h b/libstdc++-v3/include/ext/new_allocator.h index ee69953..cff9f1d 100644 --- a/libstdc++-v3/include/ext/new_allocator.h +++ b/libstdc++-v3/include/ext/new_allocator.h @@ -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 diff --git a/libstdc++-v3/include/ext/rc_string_base.h b/libstdc++-v3/include/ext/rc_string_base.h index 529035c..2cf5fb0 100644 --- a/libstdc++-v3/include/ext/rc_string_base.h +++ b/libstdc++-v3/include/ext/rc_string_base.h @@ -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() diff --git a/libstdc++-v3/include/ext/rope b/libstdc++-v3/include/ext/rope index 0788dee..bfb29e1 100644 --- a/libstdc++-v3/include/ext/rope +++ b/libstdc++-v3/include/ext/rope @@ -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, diff --git a/libstdc++-v3/include/ext/slist b/libstdc++-v3/include/ext/slist index ff2ea15..93522ca 100644 --- a/libstdc++-v3/include/ext/slist +++ b/libstdc++-v3/include/ext/slist @@ -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 diff --git a/libstdc++-v3/include/ext/sso_string_base.h b/libstdc++-v3/include/ext/sso_string_base.h index beae593..e86d810 100644 --- a/libstdc++-v3/include/ext/sso_string_base.h +++ b/libstdc++-v3/include/ext/sso_string_base.h @@ -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 diff --git a/libstdc++-v3/include/ext/throw_allocator.h b/libstdc++-v3/include/ext/throw_allocator.h index 38e80f7..f5da751 100644 --- a/libstdc++-v3/include/ext/throw_allocator.h +++ b/libstdc++-v3/include/ext/throw_allocator.h @@ -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 diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index 5942218..23ccf15 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -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; diff --git a/libstdc++-v3/include/ext/vstring_util.h b/libstdc++-v3/include/ext/vstring_util.h index 5d00b16..f539a6b 100644 --- a/libstdc++-v3/include/ext/vstring_util.h +++ b/libstdc++-v3/include/ext/vstring_util.h @@ -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:: |