Skip to content

Commit 7c69491

Browse files
authored
[libc++] Simplify aligned_storage (llvm#114665)
The main template of `aligned_storage` is only ever used when we have extremely overaligned types (> 16384), so we effectively only ever use the specializations currently. This means that we only instantiate the main template for overaligned types. Instead of doing this dance, we can just define the main template to use `_ALIGNAS`, just like the specializations. This makes the implementation of `aligned_storage` significantly less confusing.
1 parent 1c6ec29 commit 7c69491

File tree

1 file changed

+1
-49
lines changed

1 file changed

+1
-49
lines changed

libcxx/include/__type_traits/aligned_storage.h

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <__config>
1313
#include <__cstddef/size_t.h>
14-
#include <__type_traits/conditional.h>
1514
#include <__type_traits/integral_constant.h>
1615
#include <__type_traits/nat.h>
1716
#include <__type_traits/type_list.h>
@@ -50,22 +49,6 @@ typedef __type_list<__align_type<unsigned char>,
5049
> > > > > > > > > > __all_types;
5150
// clang-format on
5251

53-
template <size_t _Align>
54-
struct _ALIGNAS(_Align) __fallback_overaligned {};
55-
56-
template <class _TL, size_t _Align>
57-
struct __find_pod;
58-
59-
template <class _Hp, size_t _Align>
60-
struct __find_pod<__type_list<_Hp, __nat>, _Align> {
61-
typedef __conditional_t<_Align == _Hp::value, typename _Hp::type, __fallback_overaligned<_Align> > type;
62-
};
63-
64-
template <class _Hp, class _Tp, size_t _Align>
65-
struct __find_pod<__type_list<_Hp, _Tp>, _Align> {
66-
typedef __conditional_t<_Align == _Hp::value, typename _Hp::type, typename __find_pod<_Tp, _Align>::type> type;
67-
};
68-
6952
template <class _TL, size_t _Len>
7053
struct __find_max_align;
7154

@@ -88,9 +71,7 @@ struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
8871

8972
template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
9073
struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS aligned_storage {
91-
typedef typename __find_pod<__all_types, _Align>::type _Aligner;
92-
union type {
93-
_Aligner __align;
74+
union _ALIGNAS(_Align) type {
9475
unsigned char __data[(_Len + _Align - 1) / _Align * _Align];
9576
};
9677
};
@@ -104,35 +85,6 @@ _LIBCPP_SUPPRESS_DEPRECATED_POP
10485

10586
#endif
10687

107-
#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
108-
template <size_t _Len> \
109-
struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n> { \
110-
struct _ALIGNAS(n) type { \
111-
unsigned char __lx[(_Len + n - 1) / n * n]; \
112-
}; \
113-
}
114-
115-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
116-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
117-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
118-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
119-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
120-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
121-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
122-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
123-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
124-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
125-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
126-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
127-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
128-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
129-
// PE/COFF does not support alignment beyond 8192 (=0x2000)
130-
#if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
131-
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
132-
#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF)
133-
134-
#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
135-
13688
_LIBCPP_END_NAMESPACE_STD
13789

13890
#endif // _LIBCPP___TYPE_TRAITS_ALIGNED_STORAGE_H

0 commit comments

Comments
 (0)