[libcxx-commits] [libcxx] 9474e09 - [libc++] Granularize the <new> header (#119270)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 13 11:18:01 PST 2024


Author: Louis Dionne
Date: 2024-12-13T14:17:56-05:00
New Revision: 9474e09459189fbed30f329a669f9c14979c5367

URL: https://github.com/llvm/llvm-project/commit/9474e09459189fbed30f329a669f9c14979c5367
DIFF: https://github.com/llvm/llvm-project/commit/9474e09459189fbed30f329a669f9c14979c5367.diff

LOG: [libc++] Granularize the <new> header (#119270)

This disentangles the code which previously had a mix of many #ifdefs, a
non-versioned namespace and a versioned namespace. It also makes it
clearer which parts of <new> are implemented on Windows by including <new.h>.

Added: 
    libcxx/include/__new/align_val_t.h
    libcxx/include/__new/allocate.h
    libcxx/include/__new/destroying_delete_t.h
    libcxx/include/__new/exceptions.h
    libcxx/include/__new/global_new_delete.h
    libcxx/include/__new/interference_size.h
    libcxx/include/__new/launder.h
    libcxx/include/__new/new_handler.h
    libcxx/include/__new/nothrow_t.h
    libcxx/include/__new/placement_new_delete.h

Modified: 
    libcxx/include/CMakeLists.txt
    libcxx/include/__hash_table
    libcxx/include/__memory/allocator.h
    libcxx/include/__memory/builtin_new_allocator.h
    libcxx/include/__memory/construct_at.h
    libcxx/include/__memory/shared_ptr.h
    libcxx/include/__memory/uninitialized_algorithms.h
    libcxx/include/__utility/small_buffer.h
    libcxx/include/array
    libcxx/include/charconv
    libcxx/include/forward_list
    libcxx/include/future
    libcxx/include/list
    libcxx/include/module.modulemap
    libcxx/include/new
    libcxx/test/libcxx/transitive_includes/cxx03.csv
    libcxx/test/libcxx/transitive_includes/cxx11.csv
    libcxx/test/libcxx/transitive_includes/cxx14.csv
    libcxx/test/libcxx/transitive_includes/cxx23.csv
    libcxx/test/libcxx/transitive_includes/cxx26.csv
    libcxx/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp
    libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp
    libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
    libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
    libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 561ce4b42fb250..10e5a15c855c81 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -581,6 +581,16 @@ set(files
   __mutex/once_flag.h
   __mutex/tag_types.h
   __mutex/unique_lock.h
+  __new/align_val_t.h
+  __new/allocate.h
+  __new/destroying_delete_t.h
+  __new/exceptions.h
+  __new/global_new_delete.h
+  __new/interference_size.h
+  __new/launder.h
+  __new/new_handler.h
+  __new/nothrow_t.h
+  __new/placement_new_delete.h
   __node_handle
   __numeric/accumulate.h
   __numeric/adjacent_
diff erence.h

diff  --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index a0c72f4c205413..fe7465a84c4024 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -26,6 +26,7 @@
 #include <__memory/pointer_traits.h>
 #include <__memory/swap_allocator.h>
 #include <__memory/unique_ptr.h>
+#include <__new/launder.h>
 #include <__type_traits/can_extract_key.h>
 #include <__type_traits/conditional.h>
 #include <__type_traits/enable_if.h>
@@ -46,7 +47,6 @@
 #include <__utility/swap.h>
 #include <cstring>
 #include <limits>
-#include <new> // __launder
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header

diff  --git a/libcxx/include/__memory/allocator.h b/libcxx/include/__memory/allocator.h
index ddb4179940b8b1..1fcaf6402667e1 100644
--- a/libcxx/include/__memory/allocator.h
+++ b/libcxx/include/__memory/allocator.h
@@ -12,6 +12,7 @@
 
 #include <__config>
 #include <__cstddef/ptr
diff _t.h>
+#include <__cstddef/size_t.h>
 #include <__memory/addressof.h>
 #include <__memory/allocate_at_least.h>
 #include <__memory/allocator_traits.h>

diff  --git a/libcxx/include/__memory/builtin_new_allocator.h b/libcxx/include/__memory/builtin_new_allocator.h
index 128288efb05bc1..b1611b12bff03e 100644
--- a/libcxx/include/__memory/builtin_new_allocator.h
+++ b/libcxx/include/__memory/builtin_new_allocator.h
@@ -10,6 +10,7 @@
 #define _LIBCPP___MEMORY_BUILTIN_NEW_ALLOCATOR_H
 
 #include <__config>
+#include <__cstddef/size_t.h>
 #include <__memory/unique_ptr.h>
 #include <new>
 

diff  --git a/libcxx/include/__memory/construct_at.h b/libcxx/include/__memory/construct_at.h
index d8c97467f54b9f..1f129d17970b19 100644
--- a/libcxx/include/__memory/construct_at.h
+++ b/libcxx/include/__memory/construct_at.h
@@ -14,12 +14,12 @@
 #include <__config>
 #include <__iterator/access.h>
 #include <__memory/addressof.h>
+#include <__new/placement_new_delete.h>
 #include <__type_traits/enable_if.h>
 #include <__type_traits/is_array.h>
 #include <__utility/declval.h>
 #include <__utility/forward.h>
 #include <__utility/move.h>
-#include <new>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #  pragma GCC system_header

diff  --git a/libcxx/include/__memory/shared_ptr.h b/libcxx/include/__memory/shared_ptr.h
index 5c34f2efc5730e..4fa75af4ccc86d 100644
--- a/libcxx/include/__memory/shared_ptr.h
+++ b/libcxx/include/__memory/shared_ptr.h
@@ -43,6 +43,7 @@
 #include <__type_traits/is_bounded_array.h>
 #include <__type_traits/is_constructible.h>
 #include <__type_traits/is_convertible.h>
+#include <__type_traits/is_function.h>
 #include <__type_traits/is_reference.h>
 #include <__type_traits/is_same.h>
 #include <__type_traits/is_unbounded_array.h>

diff  --git a/libcxx/include/__memory/uninitialized_algorithms.h b/libcxx/include/__memory/uninitialized_algorithms.h
index 71c7ed94fec13e..25d192c7718857 100644
--- a/libcxx/include/__memory/uninitialized_algorithms.h
+++ b/libcxx/include/__memory/uninitialized_algorithms.h
@@ -15,6 +15,7 @@
 #include <__algorithm/unwrap_iter.h>
 #include <__algorithm/unwrap_range.h>
 #include <__config>
+#include <__cstddef/size_t.h>
 #include <__iterator/iterator_traits.h>
 #include <__iterator/reverse_iterator.h>
 #include <__memory/addressof.h>

diff  --git a/libcxx/include/__new/align_val_t.h b/libcxx/include/__new/align_val_t.h
new file mode 100644
index 00000000000000..ffb4e36a8bcd88
--- /dev/null
+++ b/libcxx/include/__new/align_val_t.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___NEW_ALIGN_VAL_T_H
+#define _LIBCPP___NEW_ALIGN_VAL_T_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+// purposefully not using versioning namespace
+namespace std {
+#if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION && !defined(_LIBCPP_ABI_VCRUNTIME)
+#  ifndef _LIBCPP_CXX03_LANG
+enum class align_val_t : size_t {};
+#  else
+enum align_val_t { __zero = 0, __max = (size_t)-1 };
+#  endif
+#endif
+} // namespace std
+
+#endif // _LIBCPP___NEW_ALIGN_VAL_T_H

diff  --git a/libcxx/include/__new/allocate.h b/libcxx/include/__new/allocate.h
new file mode 100644
index 00000000000000..71dffc1776eff3
--- /dev/null
+++ b/libcxx/include/__new/allocate.h
@@ -0,0 +1,101 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___NEW_ALLOCATE_H
+#define _LIBCPP___NEW_ALLOCATE_H
+
+#include <__config>
+#include <__cstddef/max_align_t.h>
+#include <__cstddef/size_t.h>
+#include <__new/align_val_t.h>
+#include <__new/global_new_delete.h> // for _LIBCPP_HAS_SIZED_DEALLOCATION
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+_LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
+#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
+  return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
+#else
+  return __align > _LIBCPP_ALIGNOF(max_align_t);
+#endif
+}
+
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI void* __libcpp_operator_new(_Args... __args) {
+#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
+  return __builtin_operator_new(__args...);
+#else
+  return ::operator new(__args...);
+#endif
+}
+
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) _NOEXCEPT {
+#if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
+  __builtin_operator_delete(__args...);
+#else
+  ::operator delete(__args...);
+#endif
+}
+
+inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_allocate(size_t __size, size_t __align) {
+#if _LIBCPP_HAS_ALIGNED_ALLOCATION
+  if (__is_overaligned_for_new(__align)) {
+    const align_val_t __align_val = static_cast<align_val_t>(__align);
+    return __libcpp_operator_new(__size, __align_val);
+  }
+#endif
+
+  (void)__align;
+  return __libcpp_operator_new(__size);
+}
+
+template <class... _Args>
+_LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t __size, _Args... __args) _NOEXCEPT {
+#if !_LIBCPP_HAS_SIZED_DEALLOCATION
+  (void)__size;
+  return std::__libcpp_operator_delete(__ptr, __args...);
+#else
+  return std::__libcpp_operator_delete(__ptr, __size, __args...);
+#endif
+}
+
+inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) _NOEXCEPT {
+#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
+  (void)__align;
+  return __do_deallocate_handle_size(__ptr, __size);
+#else
+  if (__is_overaligned_for_new(__align)) {
+    const align_val_t __align_val = static_cast<align_val_t>(__align);
+    return __do_deallocate_handle_size(__ptr, __size, __align_val);
+  } else {
+    return __do_deallocate_handle_size(__ptr, __size);
+  }
+#endif
+}
+
+inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(void* __ptr, size_t __align) _NOEXCEPT {
+#if !_LIBCPP_HAS_ALIGNED_ALLOCATION
+  (void)__align;
+  return __libcpp_operator_delete(__ptr);
+#else
+  if (__is_overaligned_for_new(__align)) {
+    const align_val_t __align_val = static_cast<align_val_t>(__align);
+    return __libcpp_operator_delete(__ptr, __align_val);
+  } else {
+    return __libcpp_operator_delete(__ptr);
+  }
+#endif
+}
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NEW_ALLOCATE_H

diff  --git a/libcxx/include/__new/destroying_delete_t.h b/libcxx/include/__new/destroying_delete_t.h
new file mode 100644
index 00000000000000..7fca4f6c68b212
--- /dev/null
+++ b/libcxx/include/__new/destroying_delete_t.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___NEW_DESTROYING_DELETE_T_H
+#define _LIBCPP___NEW_DESTROYING_DELETE_T_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 20
+// purposefully not using versioning namespace
+namespace std {
+// Enable the declaration even if the compiler doesn't support the language
+// feature.
+struct destroying_delete_t {
+  explicit destroying_delete_t() = default;
+};
+inline constexpr destroying_delete_t destroying_delete{};
+} // namespace std
+#endif
+
+#endif // _LIBCPP___NEW_DESTROYING_DELETE_T_H

diff  --git a/libcxx/include/__new/exceptions.h b/libcxx/include/__new/exceptions.h
new file mode 100644
index 00000000000000..053feecb036787
--- /dev/null
+++ b/libcxx/include/__new/exceptions.h
@@ -0,0 +1,74 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___NEW_EXCEPTIONS_H
+#define _LIBCPP___NEW_EXCEPTIONS_H
+
+#include <__config>
+#include <__exception/exception.h>
+#include <__verbose_abort>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+// purposefully not using versioning namespace
+namespace std {
+#if !defined(_LIBCPP_ABI_VCRUNTIME)
+
+class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
+public:
+  bad_alloc() _NOEXCEPT;
+  _LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT            = default;
+  _LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
+  ~bad_alloc() _NOEXCEPT override;
+  const char* what() const _NOEXCEPT override;
+};
+
+class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {
+public:
+  bad_array_new_length() _NOEXCEPT;
+  _LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT            = default;
+  _LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
+  ~bad_array_new_length() _NOEXCEPT override;
+  const char* what() const _NOEXCEPT override;
+};
+
+#elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
+
+// When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
+// since they would normally be provided in vcruntime_exception.h
+class bad_alloc : public exception {
+public:
+  bad_alloc() noexcept : exception("bad allocation") {}
+
+private:
+  friend class bad_array_new_length;
+
+  bad_alloc(char const* const __message) noexcept : exception(__message) {}
+};
+
+class bad_array_new_length : public bad_alloc {
+public:
+  bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
+};
+
+#endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
+
+[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
+
+[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
+#if _LIBCPP_HAS_EXCEPTIONS
+  throw bad_array_new_length();
+#else
+  _LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
+#endif
+}
+} // namespace std
+
+#endif // _LIBCPP___NEW_EXCEPTIONS_H

diff  --git a/libcxx/include/__new/global_new_delete.h b/libcxx/include/__new/global_new_delete.h
new file mode 100644
index 00000000000000..7d0797e4832467
--- /dev/null
+++ b/libcxx/include/__new/global_new_delete.h
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___NEW_GLOBAL_NEW_DELETE_H
+#define _LIBCPP___NEW_GLOBAL_NEW_DELETE_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+#include <__new/align_val_t.h>
+#include <__new/exceptions.h>
+#include <__new/nothrow_t.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if defined(_LIBCPP_CXX03_LANG)
+#  define _THROW_BAD_ALLOC throw(std::bad_alloc)
+#else
+#  define _THROW_BAD_ALLOC
+#endif
+
+#if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
+#  define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 1
+#else
+#  define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 0
+#endif
+
+#if _LIBCPP_STD_VER >= 14 || _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
+#  define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 1
+#else
+#  define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 0
+#endif
+
+#if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION && _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
+#  define _LIBCPP_HAS_SIZED_DEALLOCATION 1
+#else
+#  define _LIBCPP_HAS_SIZED_DEALLOCATION 0
+#endif
+
+#if defined(_LIBCPP_ABI_VCRUNTIME)
+#  include <new.h>
+#else
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
+    _LIBCPP_NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
+#  if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
+#  endif
+
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
+    _LIBCPP_NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
+#  if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
+#  endif
+
+#  if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
+operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
+#    if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
+#    endif
+
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
+operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
+[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
+operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
+#    if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
+_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
+#    endif
+#  endif
+#endif
+
+#endif // _LIBCPP___NEW_GLOBAL_NEW_DELETE_H

diff  --git a/libcxx/include/__new/interference_size.h b/libcxx/include/__new/interference_size.h
new file mode 100644
index 00000000000000..d326c43a332034
--- /dev/null
+++ b/libcxx/include/__new/interference_size.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___NEW_INTERFERENCE_SIZE_H
+#define _LIBCPP___NEW_INTERFERENCE_SIZE_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 17
+
+#  if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
+
+inline constexpr size_t hardware_destructive_interference_size  = __GCC_DESTRUCTIVE_SIZE;
+inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
+
+#  endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
+
+#endif // _LIBCPP_STD_VER >= 17
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NEW_INTERFERENCE_SIZE_H

diff  --git a/libcxx/include/__new/launder.h b/libcxx/include/__new/launder.h
new file mode 100644
index 00000000000000..83d80015913d96
--- /dev/null
+++ b/libcxx/include/__new/launder.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___NEW_LAUNDER_H
+#define _LIBCPP___NEW_LAUNDER_H
+
+#include <__config>
+#include <__type_traits/is_function.h>
+#include <__type_traits/is_void.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+template <class _Tp>
+[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT {
+  static_assert(!(is_function<_Tp>::value), "can't launder functions");
+  static_assert(!is_void<_Tp>::value, "can't launder cv-void");
+  return __builtin_launder(__p);
+}
+
+#if _LIBCPP_STD_VER >= 17
+template <class _Tp>
+[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp* launder(_Tp* __p) noexcept {
+  return std::__launder(__p);
+}
+#endif
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___NEW_LAUNDER_H

diff  --git a/libcxx/include/__new/new_handler.h b/libcxx/include/__new/new_handler.h
new file mode 100644
index 00000000000000..c9afdab45afc13
--- /dev/null
+++ b/libcxx/include/__new/new_handler.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___NEW_NEW_HANDLER_H
+#define _LIBCPP___NEW_NEW_HANDLER_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if defined(_LIBCPP_ABI_VCRUNTIME)
+#  include <new.h>
+#else
+// purposefully not using versioning namespace
+namespace std {
+typedef void (*new_handler)();
+_LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
+_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
+} // namespace std
+#endif // _LIBCPP_ABI_VCRUNTIME
+
+#endif // _LIBCPP___NEW_NEW_HANDLER_H

diff  --git a/libcxx/include/__new/nothrow_t.h b/libcxx/include/__new/nothrow_t.h
new file mode 100644
index 00000000000000..09c2d03f66ccc4
--- /dev/null
+++ b/libcxx/include/__new/nothrow_t.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___NEW_NOTHROW_T_H
+#define _LIBCPP___NEW_NOTHROW_T_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if defined(_LIBCPP_ABI_VCRUNTIME)
+#  include <new.h>
+#else
+// purposefully not using versioning namespace
+namespace std {
+struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t {
+  explicit nothrow_t() = default;
+};
+extern _LIBCPP_EXPORTED_FROM_ABI const nothrow_t nothrow;
+} // namespace std
+#endif // _LIBCPP_ABI_VCRUNTIME
+
+#endif // _LIBCPP___NEW_NOTHROW_T_H

diff  --git a/libcxx/include/__new/placement_new_delete.h b/libcxx/include/__new/placement_new_delete.h
new file mode 100644
index 00000000000000..42c9f340367755
--- /dev/null
+++ b/libcxx/include/__new/placement_new_delete.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H
+#define _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H
+
+#include <__config>
+#include <__cstddef/size_t.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if defined(_LIBCPP_ABI_VCRUNTIME)
+#  include <new.h>
+#else
+[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
+operator new(std::size_t, void* __p) _NOEXCEPT {
+  return __p;
+}
+[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
+operator new[](std::size_t, void* __p) _NOEXCEPT {
+  return __p;
+}
+inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
+inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
+#endif
+
+#endif // _LIBCPP___NEW_PLACEMENT_NEW_DELETE_H

diff  --git a/libcxx/include/__utility/small_buffer.h b/libcxx/include/__utility/small_buffer.h
index b44b37e90e7653..405c0aed459632 100644
--- a/libcxx/include/__utility/small_buffer.h
+++ b/libcxx/include/__utility/small_buffer.h
@@ -11,6 +11,7 @@
 
 #include <__config>
 #include <__cstddef/byte.h>
+#include <__cstddef/size_t.h>
 #include <__memory/construct_at.h>
 #include <__type_traits/decay.h>
 #include <__type_traits/is_trivially_constructible.h>

diff  --git a/libcxx/include/array b/libcxx/include/array
index b65b99533cbeb6..7aed70f91fdd76 100644
--- a/libcxx/include/array
+++ b/libcxx/include/array
@@ -563,6 +563,7 @@ _LIBCPP_POP_MACROS
 #    include <concepts>
 #    include <cstdlib>
 #    include <iterator>
+#    include <new>
 #    include <type_traits>
 #    include <utility>
 #  endif

diff  --git a/libcxx/include/charconv b/libcxx/include/charconv
index 7415f4a5182dc0..258779ad0a5575 100644
--- a/libcxx/include/charconv
+++ b/libcxx/include/charconv
@@ -112,6 +112,7 @@ _LIBCPP_END_NAMESPACE_STD
 #    include <cstring>
 #    include <iosfwd>
 #    include <limits>
+#    include <new>
 #    include <type_traits>
 #  endif
 #endif // 0

diff  --git a/libcxx/include/forward_list b/libcxx/include/forward_list
index bc95b30f441fac..23e8e51632171e 100644
--- a/libcxx/include/forward_list
+++ b/libcxx/include/forward_list
@@ -216,6 +216,7 @@ template <class T, class Allocator, class Predicate>
 #  include <__memory/pointer_traits.h>
 #  include <__memory/swap_allocator.h>
 #  include <__memory_resource/polymorphic_allocator.h>
+#  include <__new/launder.h>
 #  include <__ranges/access.h>
 #  include <__ranges/concepts.h>
 #  include <__ranges/container_compatible_range.h>
@@ -235,7 +236,6 @@ template <class T, class Allocator, class Predicate>
 #  include <__utility/move.h>
 #  include <__utility/swap.h>
 #  include <limits>
-#  include <new> // __launder
 #  include <version>
 
 // standard-mandated includes

diff  --git a/libcxx/include/future b/libcxx/include/future
index 62f59682d404d3..dacf2c10a1990b 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -373,6 +373,7 @@ template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
 #    include <__chrono/steady_clock.h>
 #    include <__chrono/time_point.h>
 #    include <__condition_variable/condition_variable.h>
+#    include <__cstddef/nullptr_t.h>
 #    include <__exception/exception_ptr.h>
 #    include <__memory/addressof.h>
 #    include <__memory/allocator.h>

diff  --git a/libcxx/include/list b/libcxx/include/list
index 89863995379d9c..a9d14272742bd4 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -222,6 +222,7 @@ template <class T, class Allocator, class Predicate>
 #  include <__memory/pointer_traits.h>
 #  include <__memory/swap_allocator.h>
 #  include <__memory_resource/polymorphic_allocator.h>
+#  include <__new/launder.h>
 #  include <__ranges/access.h>
 #  include <__ranges/concepts.h>
 #  include <__ranges/container_compatible_range.h>
@@ -240,7 +241,6 @@ template <class T, class Allocator, class Predicate>
 #  include <__utility/swap.h>
 #  include <cstring>
 #  include <limits>
-#  include <new> // __launder
 #  include <version>
 
 // standard-mandated includes

diff  --git a/libcxx/include/module.modulemap b/libcxx/include/module.modulemap
index 81621f467aba71..8d862e9f9ba361 100644
--- a/libcxx/include/module.modulemap
+++ b/libcxx/include/module.modulemap
@@ -1603,6 +1603,17 @@ module std [system] {
 
   module new {
     header "new"
+    module align_val_t          { header "__new/align_val_t.h" }
+    module allocate             { header "__new/allocate.h" }
+    module destroying_delete_t  { header "__new/destroying_delete_t.h" }
+    module exceptions           { header "__new/exceptions.h" }
+    module global_new_delete    { header "__new/global_new_delete.h" }
+    module interference_size    { header "__new/interference_size.h" }
+    module launder              { header "__new/launder.h" }
+    module new_handler          { header "__new/new_handler.h" }
+    module nothrow_t            { header "__new/nothrow_t.h" }
+    module placement_new_delete { header "__new/placement_new_delete.h" }
+
     export *
   }
 

diff  --git a/libcxx/include/new b/libcxx/include/new
index 8bb7b300d08bce..8dd726f63a0e76 100644
--- a/libcxx/include/new
+++ b/libcxx/include/new
@@ -89,285 +89,30 @@ void  operator delete[](void* ptr, void*) noexcept;
 #if 0
 #else // 0
 #  include <__config>
-#  include <__cstddef/max_align_t.h>
-#  include <__cstddef/size_t.h>
-#  include <__exception/exception.h>
-#  include <__type_traits/is_function.h>
-#  include <__type_traits/is_void.h>
-#  include <__verbose_abort>
-#  include <version>
-
-#  if defined(_LIBCPP_ABI_VCRUNTIME)
-#    include <new.h>
-#  endif
-
-#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#    pragma GCC system_header
-#  endif
-
-#  if defined(__cpp_sized_deallocation) && __cpp_sized_deallocation >= 201309L
-#    define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 1
-#  else
-#    define _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION 0
-#  endif
-
-#  if _LIBCPP_STD_VER >= 14 || _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
-#    define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 1
-#  else
-#    define _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION 0
-#  endif
-
-#  if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION && _LIBCPP_HAS_LANGUAGE_SIZED_DEALLOCATION
-#    define _LIBCPP_HAS_SIZED_DEALLOCATION 1
-#  else
-#    define _LIBCPP_HAS_SIZED_DEALLOCATION 0
-#  endif
-
-namespace std // purposefully not using versioning namespace
-{
-
-#  if !defined(_LIBCPP_ABI_VCRUNTIME)
-struct _LIBCPP_EXPORTED_FROM_ABI nothrow_t {
-  explicit nothrow_t() = default;
-};
-extern _LIBCPP_EXPORTED_FROM_ABI const nothrow_t nothrow;
-
-class _LIBCPP_EXPORTED_FROM_ABI bad_alloc : public exception {
-public:
-  bad_alloc() _NOEXCEPT;
-  _LIBCPP_HIDE_FROM_ABI bad_alloc(const bad_alloc&) _NOEXCEPT            = default;
-  _LIBCPP_HIDE_FROM_ABI bad_alloc& operator=(const bad_alloc&) _NOEXCEPT = default;
-  ~bad_alloc() _NOEXCEPT override;
-  const char* what() const _NOEXCEPT override;
-};
-
-class _LIBCPP_EXPORTED_FROM_ABI bad_array_new_length : public bad_alloc {
-public:
-  bad_array_new_length() _NOEXCEPT;
-  _LIBCPP_HIDE_FROM_ABI bad_array_new_length(const bad_array_new_length&) _NOEXCEPT            = default;
-  _LIBCPP_HIDE_FROM_ABI bad_array_new_length& operator=(const bad_array_new_length&) _NOEXCEPT = default;
-  ~bad_array_new_length() _NOEXCEPT override;
-  const char* what() const _NOEXCEPT override;
-};
-
-typedef void (*new_handler)();
-_LIBCPP_EXPORTED_FROM_ABI new_handler set_new_handler(new_handler) _NOEXCEPT;
-_LIBCPP_EXPORTED_FROM_ABI new_handler get_new_handler() _NOEXCEPT;
-
-#  elif defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0 // !_LIBCPP_ABI_VCRUNTIME
-
-// When _HAS_EXCEPTIONS == 0, these complete definitions are needed,
-// since they would normally be provided in vcruntime_exception.h
-class bad_alloc : public exception {
-public:
-  bad_alloc() noexcept : exception("bad allocation") {}
-
-private:
-  friend class bad_array_new_length;
+#  include <__new/align_val_t.h>
+#  include <__new/allocate.h>
+#  include <__new/exceptions.h>
+#  include <__new/global_new_delete.h>
+#  include <__new/new_handler.h>
+#  include <__new/nothrow_t.h>
+#  include <__new/placement_new_delete.h>
 
-  bad_alloc(char const* const __message) noexcept : exception(__message) {}
-};
-
-class bad_array_new_length : public bad_alloc {
-public:
-  bad_array_new_length() noexcept : bad_alloc("bad array new length") {}
-};
-#  endif // defined(_LIBCPP_ABI_VCRUNTIME) && defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS == 0
-
-[[__noreturn__]] _LIBCPP_EXPORTED_FROM_ABI void __throw_bad_alloc(); // not in C++ spec
-
-[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_bad_array_new_length() {
-#  if _LIBCPP_HAS_EXCEPTIONS
-  throw bad_array_new_length();
-#  else
-  _LIBCPP_VERBOSE_ABORT("bad_array_new_length was thrown in -fno-exceptions mode");
-#  endif
-}
-
-#  if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION && !defined(_LIBCPP_ABI_VCRUNTIME)
-#    ifndef _LIBCPP_CXX03_LANG
-enum class align_val_t : size_t {};
-#    else
-enum align_val_t { __zero = 0, __max = (size_t)-1 };
-#    endif
+#  if _LIBCPP_STD_VER >= 17
+#    include <__new/interference_size.h>
+#    include <__new/launder.h>
 #  endif
 
 #  if _LIBCPP_STD_VER >= 20
-// Enable the declaration even if the compiler doesn't support the language
-// feature.
-struct destroying_delete_t {
-  explicit destroying_delete_t() = default;
-};
-inline constexpr destroying_delete_t destroying_delete{};
-#  endif // _LIBCPP_STD_VER >= 20
-
-} // namespace std
-
-#  if defined(_LIBCPP_CXX03_LANG)
-#    define _THROW_BAD_ALLOC throw(std::bad_alloc)
-#  else
-#    define _THROW_BAD_ALLOC
-#  endif
-
-#  if !defined(_LIBCPP_ABI_VCRUNTIME)
-
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
-    _LIBCPP_NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
-#    if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
-#    endif
-
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT
-    _LIBCPP_NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
-#    if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
-#    endif
-
-#    if _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
-operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
-#      if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
-#      endif
-
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
-operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
-[[__nodiscard__]] _LIBCPP_OVERRIDABLE_FUNC_VIS void*
-operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
-#      if _LIBCPP_HAS_LIBRARY_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
-#      endif
-#    endif
-
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
-operator new(std::size_t, void* __p) _NOEXCEPT {
-  return __p;
-}
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 void*
-operator new[](std::size_t, void* __p) _NOEXCEPT {
-  return __p;
-}
-inline _LIBCPP_HIDE_FROM_ABI void operator delete(void*, void*) _NOEXCEPT {}
-inline _LIBCPP_HIDE_FROM_ABI void operator delete[](void*, void*) _NOEXCEPT {}
-
-#  endif // !_LIBCPP_ABI_VCRUNTIME
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-_LIBCPP_CONSTEXPR inline _LIBCPP_HIDE_FROM_ABI bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
-#  ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
-  return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
-#  else
-  return __align > _LIBCPP_ALIGNOF(max_align_t);
-#  endif
-}
-
-template <class... _Args>
-_LIBCPP_HIDE_FROM_ABI void* __libcpp_operator_new(_Args... __args) {
-#  if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
-  return __builtin_operator_new(__args...);
-#  else
-  return ::operator new(__args...);
-#  endif
-}
-
-template <class... _Args>
-_LIBCPP_HIDE_FROM_ABI void __libcpp_operator_delete(_Args... __args) _NOEXCEPT {
-#  if __has_builtin(__builtin_operator_new) && __has_builtin(__builtin_operator_delete)
-  __builtin_operator_delete(__args...);
-#  else
-  ::operator delete(__args...);
-#  endif
-}
-
-inline _LIBCPP_HIDE_FROM_ABI void* __libcpp_allocate(size_t __size, size_t __align) {
-#  if _LIBCPP_HAS_ALIGNED_ALLOCATION
-  if (__is_overaligned_for_new(__align)) {
-    const align_val_t __align_val = static_cast<align_val_t>(__align);
-    return __libcpp_operator_new(__size, __align_val);
-  }
-#  endif
-
-  (void)__align;
-  return __libcpp_operator_new(__size);
-}
-
-template <class... _Args>
-_LIBCPP_HIDE_FROM_ABI void __do_deallocate_handle_size(void* __ptr, size_t __size, _Args... __args) _NOEXCEPT {
-#  if !_LIBCPP_HAS_SIZED_DEALLOCATION
-  (void)__size;
-  return std::__libcpp_operator_delete(__ptr, __args...);
-#  else
-  return std::__libcpp_operator_delete(__ptr, __size, __args...);
-#  endif
-}
-
-inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) _NOEXCEPT {
-#  if !_LIBCPP_HAS_ALIGNED_ALLOCATION
-  (void)__align;
-  return __do_deallocate_handle_size(__ptr, __size);
-#  else
-  if (__is_overaligned_for_new(__align)) {
-    const align_val_t __align_val = static_cast<align_val_t>(__align);
-    return __do_deallocate_handle_size(__ptr, __size, __align_val);
-  } else {
-    return __do_deallocate_handle_size(__ptr, __size);
-  }
-#  endif
-}
-
-inline _LIBCPP_HIDE_FROM_ABI void __libcpp_deallocate_unsized(void* __ptr, size_t __align) _NOEXCEPT {
-#  if !_LIBCPP_HAS_ALIGNED_ALLOCATION
-  (void)__align;
-  return __libcpp_operator_delete(__ptr);
-#  else
-  if (__is_overaligned_for_new(__align)) {
-    const align_val_t __align_val = static_cast<align_val_t>(__align);
-    return __libcpp_operator_delete(__ptr, __align_val);
-  } else {
-    return __libcpp_operator_delete(__ptr);
-  }
+#    include <__new/destroying_delete_t.h>
 #  endif
-}
 
-template <class _Tp>
-[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT {
-  static_assert(!(is_function<_Tp>::value), "can't launder functions");
-  static_assert(!is_void<_Tp>::value, "can't launder cv-void");
-  return __builtin_launder(__p);
-}
+// feature-test macros
+#  include <version>
 
-#  if _LIBCPP_STD_VER >= 17
-template <class _Tp>
-[[nodiscard]] inline _LIBCPP_HIDE_FROM_ABI constexpr _Tp* launder(_Tp* __p) noexcept {
-  return std::__launder(__p);
-}
+#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#    pragma GCC system_header
 #  endif
 
-#  if _LIBCPP_STD_VER >= 17
-
-#    if defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
-
-inline constexpr size_t hardware_destructive_interference_size  = __GCC_DESTRUCTIVE_SIZE;
-inline constexpr size_t hardware_constructive_interference_size = __GCC_CONSTRUCTIVE_SIZE;
-
-#    endif // defined(__GCC_DESTRUCTIVE_SIZE) && defined(__GCC_CONSTRUCTIVE_SIZE)
-
-#  endif // _LIBCPP_STD_VER >= 17
-
-_LIBCPP_END_NAMESPACE_STD
-
 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
 #    include <cstddef>
 #    include <cstdlib>

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx03.csv b/libcxx/test/libcxx/transitive_includes/cxx03.csv
index 801f6cbf9060f8..ec5db90597d927 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx03.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx03.csv
@@ -250,6 +250,7 @@ charconv cstdlib
 charconv cstring
 charconv iosfwd
 charconv limits
+charconv new
 charconv type_traits
 charconv version
 chrono algorithm

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx11.csv b/libcxx/test/libcxx/transitive_includes/cxx11.csv
index 801f6cbf9060f8..ec5db90597d927 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx11.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx11.csv
@@ -250,6 +250,7 @@ charconv cstdlib
 charconv cstring
 charconv iosfwd
 charconv limits
+charconv new
 charconv type_traits
 charconv version
 chrono algorithm

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx14.csv b/libcxx/test/libcxx/transitive_includes/cxx14.csv
index 9146a7079ee1e9..95024df0590b84 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx14.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx14.csv
@@ -255,6 +255,7 @@ charconv cstdlib
 charconv cstring
 charconv iosfwd
 charconv limits
+charconv new
 charconv type_traits
 charconv version
 chrono algorithm

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx23.csv b/libcxx/test/libcxx/transitive_includes/cxx23.csv
index 096c321672474d..838ed411a7e387 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx23.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx23.csv
@@ -28,7 +28,6 @@ array cwchar
 array cwctype
 array initializer_list
 array limits
-array new
 array stdexcept
 array version
 atomic climits
@@ -43,7 +42,6 @@ barrier cstdint
 barrier cstring
 barrier ctime
 barrier limits
-barrier new
 barrier ratio
 barrier version
 bit cstdint
@@ -102,7 +100,6 @@ charconv cerrno
 charconv cstdint
 charconv initializer_list
 charconv limits
-charconv new
 charconv version
 chrono array
 chrono bitset
@@ -271,7 +268,6 @@ exception version
 execution version
 expected cstdint
 expected initializer_list
-expected new
 expected version
 experimental/iterator bitset
 experimental/iterator cctype
@@ -672,7 +668,6 @@ mdspan cwchar
 mdspan cwctype
 mdspan initializer_list
 mdspan limits
-mdspan new
 mdspan span
 mdspan stdexcept
 mdspan version
@@ -882,7 +877,6 @@ regex version
 scoped_allocator compare
 scoped_allocator cstdint
 scoped_allocator limits
-scoped_allocator new
 scoped_allocator tuple
 scoped_allocator version
 semaphore climits
@@ -1018,7 +1012,6 @@ string_view cwctype
 string_view initializer_list
 string_view iosfwd
 string_view limits
-string_view new
 string_view stdexcept
 string_view version
 strstream bitset

diff  --git a/libcxx/test/libcxx/transitive_includes/cxx26.csv b/libcxx/test/libcxx/transitive_includes/cxx26.csv
index 74d912e5fe3a31..cb48eb32c26b3c 100644
--- a/libcxx/test/libcxx/transitive_includes/cxx26.csv
+++ b/libcxx/test/libcxx/transitive_includes/cxx26.csv
@@ -28,7 +28,6 @@ array cwchar
 array cwctype
 array initializer_list
 array limits
-array new
 array stdexcept
 array version
 atomic climits
@@ -43,7 +42,6 @@ barrier cstdint
 barrier cstring
 barrier ctime
 barrier limits
-barrier new
 barrier ratio
 barrier version
 bit cstdint
@@ -102,7 +100,6 @@ charconv cerrno
 charconv cstdint
 charconv initializer_list
 charconv limits
-charconv new
 charconv version
 chrono array
 chrono bitset
@@ -271,7 +268,6 @@ exception version
 execution version
 expected cstdint
 expected initializer_list
-expected new
 expected version
 experimental/iterator bitset
 experimental/iterator cctype
@@ -671,7 +667,6 @@ mdspan cwchar
 mdspan cwctype
 mdspan initializer_list
 mdspan limits
-mdspan new
 mdspan span
 mdspan stdexcept
 mdspan version
@@ -881,7 +876,6 @@ regex version
 scoped_allocator compare
 scoped_allocator cstdint
 scoped_allocator limits
-scoped_allocator new
 scoped_allocator tuple
 scoped_allocator version
 semaphore climits
@@ -1017,7 +1011,6 @@ string_view cwctype
 string_view initializer_list
 string_view iosfwd
 string_view limits
-string_view new
 string_view stdexcept
 string_view version
 strstream bitset

diff  --git a/libcxx/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp b/libcxx/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp
index a4016bff741390..9705513ae54b04 100644
--- a/libcxx/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/alloc.errors/bad.alloc/bad_alloc.pass.cpp
@@ -9,8 +9,9 @@
 // test bad_alloc
 
 #include <new>
-#include <type_traits>
 #include <cassert>
+#include <exception>
+#include <type_traits>
 
 #include "test_macros.h"
 

diff  --git a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp
index e27fad95becb77..1f7b08ec641c31 100644
--- a/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_array.pass.cpp
@@ -10,6 +10,7 @@
 
 #include <new>
 #include <cassert>
+#include <cstddef>
 
 #include "test_macros.h"
 

diff  --git a/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
index f8f04112fa82f1..4f2b627b8601a9 100644
--- a/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
+++ b/libcxx/test/std/language.support/support.dynamic/ptr.launder/launder.types.verify.cpp
@@ -20,17 +20,17 @@
 
 void foo() {}
 
-int main(int, char**)
-{
-    void *p = nullptr;
-    (void) std::launder((               void *) nullptr);
-    (void) std::launder((const          void *) nullptr);
-    (void) std::launder((      volatile void *) nullptr);
-    (void) std::launder((const volatile void *) nullptr);  // expected-error-re at new:* 4 {{static assertion failed{{.*}}can't launder cv-void}}
-    // expected-error at new:* 0-4 {{void pointer argument to '__builtin_launder' is not allowed}}
-
-    (void) std::launder(foo);                              // expected-error-re at new:* 1 {{static assertion failed{{.*}}can't launder functions}}
-    // expected-error at new:* 0-1 {{function pointer argument to '__builtin_launder' is not allowed}}
+int main(int, char**) {
+  void* p = nullptr;
+  (void)std::launder((void*)nullptr);
+  (void)std::launder((const void*)nullptr);
+  (void)std::launder((volatile void*)nullptr);
+  (void)std::launder(
+      (const volatile void*)nullptr); // expected-error-re@*:* 4 {{static assertion failed{{.*}}can't launder cv-void}}
+  // expected-error@*:* 0-4 {{void pointer argument to '__builtin_launder' is not allowed}}
+
+  (void)std::launder(foo); // expected-error-re@*:* 1 {{static assertion failed{{.*}}can't launder functions}}
+  // expected-error@*:* 0-1 {{function pointer argument to '__builtin_launder' is not allowed}}
 
   return 0;
 }

diff  --git a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
index 2b11bd7f48dd7f..eaeaaa50401e9a 100644
--- a/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
+++ b/libcxx/test/std/utilities/memory/default.allocator/allocator.members/allocate.size.pass.cpp
@@ -14,6 +14,7 @@
 
 #include <memory>
 #include <cassert>
+#include <cstddef>
 #include <new>
 
 #include "test_macros.h"

diff  --git a/libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp b/libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp
index b3ecf485d3951d..746dbaad053ef7 100644
--- a/libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp
+++ b/libcxxabi/test/cxa_vec_new_overflow_PR41395.pass.cpp
@@ -12,8 +12,9 @@
 // XFAIL: using-built-library-before-llvm-9
 
 #include "cxxabi.h"
-#include <new>
 #include <cassert>
+#include <cstddef>
+#include <new>
 
 void dummy_ctor(void*) { assert(false && "should not be called"); }
 void dummy_dtor(void*) { assert(false && "should not be called"); }


        


More information about the libcxx-commits mailing list