Skip to content

Commit f1025e6

Browse files
authored
[Support] Replace deprecated std::aligned_union, NFCI. (#127417)
All std::aligned_* are deprecated in C++23. Implement the replacement suggested in P1413R3 using alignas and std::max.
1 parent eacbcbe commit f1025e6

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

llvm/include/llvm/Support/AlignOf.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,14 @@
1313
#ifndef LLVM_SUPPORT_ALIGNOF_H
1414
#define LLVM_SUPPORT_ALIGNOF_H
1515

16-
#include <type_traits>
16+
#include <algorithm>
1717

1818
namespace llvm {
1919

2020
/// A suitably aligned and sized character array member which can hold elements
2121
/// of any type.
22-
///
23-
/// This template is equivalent to std::aligned_union_t<1, ...>, but we cannot
24-
/// use it due to a bug in the MSVC x86 compiler:
25-
/// https://github.com/microsoft/STL/issues/1533
26-
/// Using `alignas` here works around the bug.
2722
template <typename T, typename... Ts> struct AlignedCharArrayUnion {
28-
using AlignedUnion = std::aligned_union_t<1, T, Ts...>;
29-
alignas(alignof(AlignedUnion)) char buffer[sizeof(AlignedUnion)];
23+
alignas(T) alignas(Ts...) char buffer[std::max({sizeof(T), sizeof(Ts)...})];
3024
};
3125

3226
} // end namespace llvm

0 commit comments

Comments
 (0)