[libcxx-commits] [libcxx] [libc++] Add __new_at_least (PR #215813)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Aug 12 08:01:09 PDT 2026


================
@@ -42,6 +43,20 @@ __libcpp_allocate(__element_count __n, [[__maybe_unused__]] size_t __align = _LI
   return static_cast<_Tp*>(__builtin_operator_new(__size));
 }
 
+template <class _Tp>
+_LIBCPP_NO_CFI __allocation_result<_Tp*>
+__libcpp_allocate_at_least(__element_count __n, [[__maybe_unused__]] size_t __align = _LIBCPP_ALIGNOF(_Tp)) {
+  size_t __size = static_cast<size_t>(__n) * sizeof(_Tp);
+#if _LIBCPP_HAS_ALIGNED_ALLOCATION
+  if (__is_overaligned_for_new(__align)) {
+    auto [__ptr, __count] = std::__new_at_least(__size, static_cast<align_val_t>(__align));
----------------
ldionne wrote:

Here we would need to only call this if `_LIBCPP_AVAILABILITY_HAS_NEW_AT_LEAST`.

https://github.com/llvm/llvm-project/pull/215813


More information about the libcxx-commits mailing list