Skip to content

Commit c0bca9c

Browse files
authored
[libc++] Remove some of the uses of aligned_storage inside the library (#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.
1 parent 5cb2c68 commit c0bca9c

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

libcxx/include/__memory/temp_value.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <__config>
1313
#include <__memory/addressof.h>
1414
#include <__memory/allocator_traits.h>
15-
#include <__type_traits/aligned_storage.h>
1615
#include <__utility/forward.h>
1716

1817
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -26,7 +25,7 @@ struct __temp_value {
2625
typedef allocator_traits<_Alloc> _Traits;
2726

2827
#ifdef _LIBCPP_CXX03_LANG
29-
typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v;
28+
_ALIGNAS_TYPE(_Tp) char __v[sizeof(_Tp)];
3029
#else
3130
union {
3231
_Tp __v;

libcxx/include/any

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ namespace std {
8888
# include <__new/allocate.h>
8989
# include <__type_traits/add_cv_quals.h>
9090
# include <__type_traits/add_pointer.h>
91-
# include <__type_traits/aligned_storage.h>
9291
# include <__type_traits/conditional.h>
9392
# include <__type_traits/decay.h>
9493
# include <__type_traits/enable_if.h>
@@ -147,14 +146,13 @@ template <class _ValueType>
147146
_LIBCPP_HIDE_FROM_ABI add_pointer_t<_ValueType> any_cast(any*) _NOEXCEPT;
148147

149148
namespace __any_imp {
150-
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
151-
using _Buffer _LIBCPP_NODEBUG = aligned_storage_t<3 * sizeof(void*), alignof(void*)>;
152-
_LIBCPP_SUPPRESS_DEPRECATED_POP
149+
inline constexpr size_t __small_buffer_size = 3 * sizeof(void*);
150+
inline constexpr size_t __small_buffer_alignment = alignof(void*);
153151

154152
template <class _Tp>
155153
using _IsSmallObject _LIBCPP_NODEBUG =
156154
integral_constant<bool,
157-
sizeof(_Tp) <= sizeof(_Buffer) && alignof(_Buffer) % alignof(_Tp) == 0 &&
155+
sizeof(_Tp) <= __small_buffer_size && alignof(_Tp) <= __small_buffer_alignment &&
158156
is_nothrow_move_constructible<_Tp>::value >;
159157

160158
enum class _Action { _Destroy, _Copy, _Move, _Get, _TypeInfo };
@@ -284,7 +282,7 @@ private:
284282
union _Storage {
285283
_LIBCPP_HIDE_FROM_ABI constexpr _Storage() : __ptr(nullptr) {}
286284
void* __ptr;
287-
__any_imp::_Buffer __buf;
285+
alignas(__any_imp::__small_buffer_alignment) char __buf[__any_imp::__small_buffer_size];
288286
};
289287

290288
_LIBCPP_HIDE_FROM_ABI void*

libcxx/include/future

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,9 @@ inline future_status __assoc_sub_state::wait_for(const chrono::duration<_Rep, _P
584584
template <class _Rp>
585585
class _LIBCPP_HIDDEN __assoc_state : public __assoc_sub_state {
586586
typedef __assoc_sub_state base;
587-
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
588-
typedef typename aligned_storage<sizeof(_Rp), _LIBCPP_ALIGNOF(_Rp)>::type _Up;
589-
_LIBCPP_SUPPRESS_DEPRECATED_POP
590587

591588
protected:
592-
_Up __value_;
589+
_ALIGNAS_TYPE(_Rp) char __value_[sizeof(_Rp)];
593590

594591
_LIBCPP_HIDE_FROM_ABI_VIRTUAL void __on_zero_shared() _NOEXCEPT override;
595592

0 commit comments

Comments
 (0)