[libcxx-commits] [libcxx] [libc++] Simplify aligned_storage (PR #114665)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 4 07:57:41 PST 2024


================
@@ -88,9 +71,7 @@ struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
 
 template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
 struct _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_TEMPLATE_VIS aligned_storage {
-  typedef typename __find_pod<__all_types, _Align>::type _Aligner;
-  union type {
-    _Aligner __align;
+  union _ALIGNAS(_Align) type {
----------------
ldionne wrote:

The patch description says:

> 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.

I got a bit confused by the first sentence, which seems to suggest that this patch is a functionality change. However, if I understand correctly, the bottom line is that this patch just ditches the specializations and always uses `_ALIGNAS`, without changing any functionality. I assume the reason for having specializations in the first place must have been for compile-time performance?

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


More information about the libcxx-commits mailing list