aboutsummaryrefslogtreecommitdiff
path: root/lib/libcxx/include/__memory/allocator.h
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-04-05 01:46:13 -0400
committerGitHub <noreply@github.com>2025-04-05 01:46:13 -0400
commit0cd31fc7ff157551cfbba5da35cd79f118d2a2e3 (patch)
treea308488f5d85184c8ec402fb3f55f1cf2704443e /lib/libcxx/include/__memory/allocator.h
parent8acedfd5baabab705946ad097746f9183ef62420 (diff)
parentcefe65c1b8abe65a22d4b68410db1be264fdeda0 (diff)
downloadzig-0cd31fc7ff157551cfbba5da35cd79f118d2a2e3.tar.gz
zig-0cd31fc7ff157551cfbba5da35cd79f118d2a2e3.zip
Merge pull request #22780 from ziglang/llvm20
LLVM 20
Diffstat (limited to 'lib/libcxx/include/__memory/allocator.h')
-rw-r--r--lib/libcxx/include/__memory/allocator.h113
1 files changed, 11 insertions, 102 deletions
diff --git a/lib/libcxx/include/__memory/allocator.h b/lib/libcxx/include/__memory/allocator.h
index 2d8624e771..191a59e661 100644
--- a/lib/libcxx/include/__memory/allocator.h
+++ b/lib/libcxx/include/__memory/allocator.h
@@ -11,17 +11,19 @@
#define _LIBCPP___MEMORY_ALLOCATOR_H
#include <__config>
+#include <__cstddef/ptrdiff_t.h>
+#include <__cstddef/size_t.h>
#include <__memory/addressof.h>
#include <__memory/allocate_at_least.h>
#include <__memory/allocator_traits.h>
+#include <__new/allocate.h>
+#include <__new/exceptions.h>
#include <__type_traits/is_const.h>
#include <__type_traits/is_constant_evaluated.h>
#include <__type_traits/is_same.h>
#include <__type_traits/is_void.h>
#include <__type_traits/is_volatile.h>
#include <__utility/forward.h>
-#include <cstddef>
-#include <new>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -47,23 +49,7 @@ public:
typedef allocator<_Up> other;
};
};
-
-// TODO(LLVM 20): Remove the escape hatch
-# ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
-template <>
-class _LIBCPP_TEMPLATE_VIS allocator<const void> {
-public:
- _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* pointer;
- _LIBCPP_DEPRECATED_IN_CXX17 typedef const void* const_pointer;
- _LIBCPP_DEPRECATED_IN_CXX17 typedef const void value_type;
-
- template <class _Up>
- struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {
- typedef allocator<_Up> other;
- };
-};
-# endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
-#endif // _LIBCPP_STD_VER <= 17
+#endif // _LIBCPP_STD_VER <= 17
// This class provides a non-trivial default constructor to the class that derives from it
// if the condition is satisfied.
@@ -109,18 +95,20 @@ public:
template <class _Up>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator(const allocator<_Up>&) _NOEXCEPT {}
- _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* allocate(size_t __n) {
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* allocate(size_t __n) {
+ static_assert(sizeof(_Tp) >= 0, "cannot allocate memory for an incomplete type");
if (__n > allocator_traits<allocator>::max_size(*this))
__throw_bad_array_new_length();
if (__libcpp_is_constant_evaluated()) {
return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
} else {
- return static_cast<_Tp*>(std::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
+ return std::__libcpp_allocate<_Tp>(__element_count(__n));
}
}
#if _LIBCPP_STD_VER >= 23
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result<_Tp*> allocate_at_least(size_t __n) {
+ static_assert(sizeof(_Tp) >= 0, "cannot allocate memory for an incomplete type");
return {allocate(__n), __n};
}
#endif
@@ -129,7 +117,7 @@ public:
if (__libcpp_is_constant_evaluated()) {
::operator delete(__p);
} else {
- std::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
+ std::__libcpp_deallocate<_Tp>(__p, __element_count(__n));
}
}
@@ -152,7 +140,7 @@ public:
return std::addressof(__x);
}
- _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 _Tp* allocate(size_t __n, const void*) {
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 _Tp* allocate(size_t __n, const void*) {
return allocate(__n);
}
@@ -169,85 +157,6 @@ public:
#endif
};
-// TODO(LLVM 20): Remove the escape hatch
-#ifdef _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
-template <class _Tp>
-class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
- : private __non_trivial_if<!is_void<_Tp>::value, allocator<const _Tp> > {
- static_assert(!is_volatile<_Tp>::value, "std::allocator does not support volatile types");
-
-public:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef const _Tp value_type;
- typedef true_type propagate_on_container_move_assignment;
-# if _LIBCPP_STD_VER <= 23 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_ALLOCATOR_MEMBERS)
- _LIBCPP_DEPRECATED_IN_CXX23 typedef true_type is_always_equal;
-# endif
-
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator() _NOEXCEPT = default;
-
- template <class _Up>
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 allocator(const allocator<_Up>&) _NOEXCEPT {}
-
- _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const _Tp* allocate(size_t __n) {
- if (__n > allocator_traits<allocator>::max_size(*this))
- __throw_bad_array_new_length();
- if (__libcpp_is_constant_evaluated()) {
- return static_cast<const _Tp*>(::operator new(__n * sizeof(_Tp)));
- } else {
- return static_cast<const _Tp*>(std::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
- }
- }
-
-# if _LIBCPP_STD_VER >= 23
- [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr allocation_result<const _Tp*> allocate_at_least(size_t __n) {
- return {allocate(__n), __n};
- }
-# endif
-
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void deallocate(const _Tp* __p, size_t __n) {
- if (__libcpp_is_constant_evaluated()) {
- ::operator delete(const_cast<_Tp*>(__p));
- } else {
- std::__libcpp_deallocate((void*)const_cast<_Tp*>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
- }
- }
-
- // C++20 Removed members
-# if _LIBCPP_STD_VER <= 17
- _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* pointer;
- _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp* const_pointer;
- _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& reference;
- _LIBCPP_DEPRECATED_IN_CXX17 typedef const _Tp& const_reference;
-
- template <class _Up>
- struct _LIBCPP_DEPRECATED_IN_CXX17 rebind {
- typedef allocator<_Up> other;
- };
-
- _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI const_pointer address(const_reference __x) const _NOEXCEPT {
- return std::addressof(__x);
- }
-
- _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 const _Tp* allocate(size_t __n, const void*) {
- return allocate(__n);
- }
-
- _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
- return size_type(~0) / sizeof(_Tp);
- }
-
- template <class _Up, class... _Args>
- _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void construct(_Up* __p, _Args&&... __args) {
- ::new ((void*)__p) _Up(std::forward<_Args>(__args)...);
- }
-
- _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI void destroy(pointer __p) { __p->~_Tp(); }
-# endif
-};
-#endif // _LIBCPP_ENABLE_REMOVED_ALLOCATOR_CONST
-
template <class _Tp, class _Up>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {