From 6111896d93e8b8847d346ec4096d3ea65b8d34fa Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Sun, 16 Feb 2025 21:58:41 +0100 Subject: [PATCH] [Support] Replace deprecated std::aligned_union, NFCI. All std::aligned_* are deprecated in C++23. Implement the replacement suggested in P1413R3 using alignas and std::max. --- llvm/include/llvm/Support/AlignOf.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/Support/AlignOf.h b/llvm/include/llvm/Support/AlignOf.h index f586d7f182aab..635bb8b101ef9 100644 --- a/llvm/include/llvm/Support/AlignOf.h +++ b/llvm/include/llvm/Support/AlignOf.h @@ -13,20 +13,14 @@ #ifndef LLVM_SUPPORT_ALIGNOF_H #define LLVM_SUPPORT_ALIGNOF_H -#include +#include namespace llvm { /// A suitably aligned and sized character array member which can hold elements /// of any type. -/// -/// This template is equivalent to std::aligned_union_t<1, ...>, but we cannot -/// use it due to a bug in the MSVC x86 compiler: -/// https://github.com/microsoft/STL/issues/1533 -/// Using `alignas` here works around the bug. template struct AlignedCharArrayUnion { - using AlignedUnion = std::aligned_union_t<1, T, Ts...>; - alignas(alignof(AlignedUnion)) char buffer[sizeof(AlignedUnion)]; + alignas(T) alignas(Ts...) char buffer[std::max({sizeof(T), sizeof(Ts)...})]; }; } // end namespace llvm