[libcxx-commits] [libcxx] [libc++] Remove some of the uses of aligned_storage inside the library (PR #161635)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 2 00:36:12 PDT 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/161635
`aligned_storage` has been deprecated and will most likely be removed in a future version of C++. This patch removes some of its uses to avoid having to work around its removal in the future.
>From ff4ed62c3bd77e04235e03c367db9f39ab4df0df Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 2 Oct 2025 09:34:19 +0200
Subject: [PATCH] [libc++] Remove some of the uses of aligned_storage inside
the library
---
libcxx/include/__memory/temp_value.h | 3 +--
libcxx/include/any | 10 ++++------
libcxx/include/future | 5 +----
3 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/libcxx/include/__memory/temp_value.h b/libcxx/include/__memory/temp_value.h
index 4a133b3fbcf6c..5285bcab9a30d 100644
--- a/libcxx/include/__memory/temp_value.h
+++ b/libcxx/include/__memory/temp_value.h
@@ -12,7 +12,6 @@
#include <__config>
#include <__memory/addressof.h>
#include <__memory/allocator_traits.h>
-#include <__type_traits/aligned_storage.h>
#include <__utility/forward.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -26,7 +25,7 @@ struct __temp_value {
typedef allocator_traits<_Alloc> _Traits;
#ifdef _LIBCPP_CXX03_LANG
- typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v;
+ _ALIGNAS_TYPE(_Tp) char __v[sizeof(_Tp)];
#else
union {
_Tp __v;
diff --git a/libcxx/include/any b/libcxx/include/any
index 89bf3cf1f7df0..b523a9c0f7e71 100644
--- a/libcxx/include/any
+++ b/libcxx/include/any
@@ -90,7 +90,6 @@ namespace std {
# include <__memory/unique_ptr.h>
# include <__type_traits/add_cv_quals.h>
# include <__type_traits/add_pointer.h>
-# include <__type_traits/aligned_storage.h>
# include <__type_traits/conditional.h>
# include <__type_traits/decay.h>
# include <__type_traits/enable_if.h>
@@ -148,14 +147,13 @@ template <class _ValueType>
_LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any*) _NOEXCEPT;
namespace __any_imp {
-_LIBCPP_SUPPRESS_DEPRECATED_PUSH
-using _Buffer _LIBCPP_NODEBUG = aligned_storage_t<3 * sizeof(void*), alignof(void*)>;
-_LIBCPP_SUPPRESS_DEPRECATED_POP
+inline constexpr size_t __small_buffer_size = 3 * sizeof(void*);
+inline constexpr size_t __small_buffer_alignment = alignof(void*);
template <class _Tp>
using _IsSmallObject _LIBCPP_NODEBUG =
integral_constant<bool,
- sizeof(_Tp) <= sizeof(_Buffer) && alignof(_Buffer) % alignof(_Tp) == 0 &&
+ sizeof(_Tp) <= __small_buffer_size && alignof(_Tp) <= __small_buffer_alignment &&
is_nothrow_move_constructible<_Tp>::value >;
enum class _Action { _Destroy, _Copy, _Move, _Get, _TypeInfo };
@@ -285,7 +283,7 @@ private:
union _Storage {
_LIBCPP_HIDE_FROM_ABI constexpr _Storage() : __ptr(nullptr) {}
void* __ptr;
- __any_imp::_Buffer __buf;
+ alignas(__any_imp::__small_buffer_alignment) char __buf[__any_imp::__small_buffer_size];
};
_LIBCPP_HIDE_FROM_ABI void*
diff --git a/libcxx/include/future b/libcxx/include/future
index 3df9dc9349a01..1fd2910827dfe 100644
--- a/libcxx/include/future
+++ b/libcxx/include/future
@@ -583,12 +583,9 @@ inline future_status __assoc_sub_state::wait_for(const chrono::duration<_Rep, _P
template <class _Rp>
class _LIBCPP_HIDDEN __assoc_state : public __assoc_sub_state {
typedef __assoc_sub_state base;
- _LIBCPP_SUPPRESS_DEPRECATED_PUSH
- typedef typename aligned_storage<sizeof(_Rp), _LIBCPP_ALIGNOF(_Rp)>::type _Up;
- _LIBCPP_SUPPRESS_DEPRECATED_POP
protected:
- _Up __value_;
+ _ALIGNAS_TYPE(_Rp) char __value_[sizeof(_Rp)];
_LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override;
More information about the libcxx-commits
mailing list