summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/alloc_traits.h
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2021-08-28 11:05:58 +0100
committerJonathan Wakely <jwakely@redhat.com>2021-08-28 14:37:19 +0100
commit754fca77e82a59d85c735a5aff49ee2b1ec4c6df (patch)
tree0b66441f995e6bc728a2714c027be484b3f5dd22 /libstdc++-v3/include/bits/alloc_traits.h
parentdd3e5859fc16701acb73f59220c8c964af9f713b (diff)
downloadgcc-754fca77e82a59d85c735a5aff49ee2b1ec4c6df.tar.gz
libstdc++: Fix std::allocator<void> for versioned namespace
Removing the allocator<void> specialization for the versioned namespace breaks _Extptr_allocator<void> because the allocator<void> specialization was still declared in <bits/memoryfwd.h>, making it an incomplete type. It wrong to remove that specialization anyway, because it is still needed pre-C++20. This removes the #if ! _GLIBCXX_INLINE_VERSION check, so that allocator<void> is still explicitly specialized for the versioned namespace, consistent with the normal unversioned namespace mode. To make _Extptr_allocator<void> usable as a ProtoAllocator, this change adds a default constructor and converting constructor. That is consistent with std::allocator<void> since C++20 (and harmless to do for earlier standards). I'm also explicitly specializing allocator_traits<allocator<void>> so that it doesn't need to use allocator<void>::construct and destroy. Doing that allows those members to be removed, further simplifying allocator<void>. That new explicit specialization can delete the allocate, deallocate and max_size members, which are always ill-formed for allocator<void>. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: * include/bits/alloc_traits.h (allocator_traits): Add explicit specialization for allocator<void>. Improve doxygen comments. * include/bits/allocator.h (allocator<void>): Restore for the versioned namespace. (allocator<void>::construct, allocator<void>::destroy): Remove. * include/ext/extptr_allocator.h (_Extptr_allocator<void>): Add default constructor and converting constructor.
Diffstat (limited to 'libstdc++-v3/include/bits/alloc_traits.h')
-rw-r--r--libstdc++-v3/include/bits/alloc_traits.h104
1 files changed, 104 insertions, 0 deletions
diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h
index 34412583064..05b584f742f 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -559,6 +559,110 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __rhs; }
};
+ /// Explicit specialization for std::allocator<void>.
+ template<>
+ struct allocator_traits<allocator<void>>
+ {
+ /// The allocator type
+ using allocator_type = allocator<void>;
+
+ /// The allocated type
+ using value_type = void;
+
+ /// The allocator's pointer type.
+ using pointer = void*;
+
+ /// The allocator's const pointer type.
+ using const_pointer = const void*;
+
+ /// The allocator's void pointer type.
+ using void_pointer = void*;
+
+ /// The allocator's const void pointer type.
+ using const_void_pointer = const void*;
+
+ /// The allocator's difference type
+ using difference_type = std::ptrdiff_t;
+
+ /// The allocator's size type
+ using size_type = std::size_t;
+
+ /// How the allocator is propagated on copy assignment
+ using propagate_on_container_copy_assignment = false_type;
+
+ /// How the allocator is propagated on move assignment
+ using propagate_on_container_move_assignment = true_type;
+
+ /// How the allocator is propagated on swap
+ using propagate_on_container_swap = false_type;
+
+ /// Whether all instances of the allocator type compare equal.
+ using is_always_equal = true_type;
+
+ template<typename _Up>
+ using rebind_alloc = allocator<_Up>;
+
+ template<typename _Up>
+ using rebind_traits = allocator_traits<allocator<_Up>>;
+
+ /// allocate is ill-formed for allocator<void>
+ static void*
+ allocate(allocator_type&, size_type, const void* = nullptr) = delete;
+
+ /// deallocate is ill-formed for allocator<void>
+ static void
+ deallocate(allocator_type&, void*, size_type) = delete;
+
+ /**
+ * @brief Construct an object of type `_Up`
+ * @param __a An allocator.
+ * @param __p Pointer to memory of suitable size and alignment for
+ * an object of type `_Up`.
+ * @param __args Constructor arguments.
+ *
+ * Calls `__a.construct(__p, std::forward<_Args>(__args)...)`
+ * in C++11, C++14 and C++17. Changed in C++20 to call
+ * `std::construct_at(__p, std::forward<_Args>(__args)...)` instead.
+ */
+ template<typename _Up, typename... _Args>
+ static _GLIBCXX20_CONSTEXPR void
+ construct(allocator_type&, _Up* __p, _Args&&... __args)
+ noexcept(std::is_nothrow_constructible<_Up, _Args...>::value)
+ {
+#if __cplusplus <= 201703L
+ ::new((void *)__p) _Up(std::forward<_Args>(__args)...);
+#else
+ std::construct_at(__p, std::forward<_Args>(__args)...);
+#endif
+ }
+
+ /**
+ * @brief Destroy an object of type `_Up`
+ * @param __a An allocator.
+ * @param __p Pointer to the object to destroy
+ *
+ * Invokes the destructor for `*__p`.
+ */
+ template<typename _Up>
+ static _GLIBCXX20_CONSTEXPR void
+ destroy(allocator_type&, _Up* __p)
+ noexcept(is_nothrow_destructible<_Up>::value)
+ { std::_Destroy(__p); }
+
+ /// max_size is ill-formed for allocator<void>
+ static size_type
+ max_size(const allocator_type&) = delete;
+
+ /**
+ * @brief Obtain an allocator to use when copying a container.
+ * @param __rhs An allocator.
+ * @return `__rhs`
+ */
+ static _GLIBCXX20_CONSTEXPR allocator_type
+ select_on_container_copy_construction(const allocator_type& __rhs)
+ { return __rhs; }
+ };
+
#if __cplusplus < 201703L
template<typename _Alloc>
inline void