2019-10-24 Jonathan Wakely <jwakely@redhat.com>
+ * include/bits/allocator.h (allocator<void>): Restore the explicit
+ specialization for C++20, but make its API consistent with the primary
+ template.
+ (allocator::~allocator()): Restore the destructor for C++20, but make
+ it constexpr.
+ * testsuite/20_util/allocator/rebind_c++20.cc: Check allocator<void>.
+ * testsuite/20_util/allocator/requirements/typedefs_c++20.cc: Likewise.
+ * testsuite/20_util/allocator/void.cc: Check that constructors and
+ destructors are trivial. Check for converting constructor in C++20.
+ * testsuite/ext/malloc_allocator/variadic_construct.cc: Simplify
+ dejagnu target selector.
+ * testsuite/ext/new_allocator/variadic_construct.cc: Likewise.
+
* include/experimental/executor (__use_future_ct, use_future_t):
Define partial specializations for std::allocator.
(__use_future_ch): Overload constructor for completion tokens using
* @{
*/
-#if __cplusplus <= 201703L
/// allocator<void> specialization.
template<>
class allocator<void>
{
public:
+ typedef void value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
+#if __cplusplus <= 201703L
typedef void* pointer;
typedef const void* const_pointer;
- typedef void value_type;
template<typename _Tp1>
struct rebind
{ typedef allocator<_Tp1> other; };
+#else
+ allocator() = default;
-#if __cplusplus >= 201103L
+ template<typename _Up>
+ constexpr
+ allocator(const allocator<_Up>&) { }
+#endif // ! C++20
+
+#if __cplusplus >= 201103L && __cplusplus <= 201703L
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2103. std::allocator propagate_on_container_move_assignment
typedef true_type propagate_on_container_move_assignment;
destroy(_Up* __p)
noexcept(noexcept(__p->~_Up()))
{ __p->~_Up(); }
-#endif // C++11
+#endif // C++11 to C++17
};
-#endif // ! C++20
/**
* @brief The @a standard allocator, as per [20.4].
_GLIBCXX20_CONSTEXPR
allocator(const allocator<_Tp1>&) _GLIBCXX_NOTHROW { }
-#if __cplusplus <= 201703L
+ _GLIBCXX20_CONSTEXPR
~allocator() _GLIBCXX_NOTHROW { }
-#endif
#if __cplusplus > 201703L
[[nodiscard,__gnu__::__always_inline__]]
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>> );
+
+using V = std::allocator_traits<Alloc<void>>;
+// Prior to C++20 this finds std::allocator<void>::rebind and so fails:
+static_assert( std::is_same_v<V::rebind_alloc<long>, Alloc<long>> );
static_assert( !has_construct<A> );
static_assert( !has_destroy<A> );
static_assert( !has_max_size<A> );
+
+using V = std::allocator<void>;
+
+static_assert( !has_pointer<V> );
+static_assert( !has_const_pointer<V> );
+static_assert( !has_reference<V> );
+static_assert( !has_const_reference<V> );
+static_assert( !has_rebind<V> );
+static_assert( !has_construct<V> );
+static_assert( !has_destroy<V> );
+static_assert( !has_max_size<V> );
std::allocator_traits<alloc_type>::destroy(a, &i);
}
+// These properties are formally unspecified, but have always been true for
+// the libstdc++ definition of allocator<void>.
+static_assert(
+ std::is_trivially_default_constructible<std::allocator<void>>::value,
+ "explicit specialization has trivial default constructor");
+static_assert(
+ std::is_trivially_copy_constructible<std::allocator<void>>::value,
+ "explicit specialization has trivial copy constructor");
+static_assert(
+ std::is_trivially_move_constructible<std::allocator<void>>::value,
+ "explicit specialization has trivial move constructor");
+static_assert(
+ std::is_trivially_destructible<std::allocator<void>>::value,
+ "explicit specialization has trivial destructor");
+
+#if __cplusplus > 201703L
+// C++20 removes the allocator<void> explicit specialization, so it can now be
+// constructed using the converting constructor from other specializations.
+static_assert( std::is_constructible_v<std::allocator<void>,
+ std::allocator<int>> );
+#endif
+
int
main()
{
-// { dg-do run { target { { c++11_only || c++14_only } || c++17_only } } }
+// { dg-do run { target { c++11 && { ! c++2a } } } }
// 2007-10-26 Paolo Carlini <pcarlini@suse.de>
-// { dg-do run { target { { c++11_only || c++14_only } || c++17_only } } }
+// { dg-do run { target { c++11 && { ! c++2a } } } }
// 2007-10-26 Paolo Carlini <pcarlini@suse.de>