[compiler-rt] [llvm] [cpp23] Remove usage of std::aligned_union<> in llvm (PR #135146)

Victor Vianna via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 10 02:09:39 PDT 2025


https://github.com/victorvianna created https://github.com/llvm/llvm-project/pull/135146

std::aligned_union<> is deprecated in C++23. See more details in the linked bug.

>From 48d4e615db0e766dcfba35513643843f2929eba0 Mon Sep 17 00:00:00 2001
From: Victor Vianna <victor.vianna10 at gmail.com>
Date: Thu, 10 Apr 2025 10:05:45 +0100
Subject: [PATCH 1/2] [cpp23] Remove std::aligned_union in TrieRawHashMap

std::aligned_union is deprecated in C++23.

Bug: https://crbug.com/388068052
---
 llvm/include/llvm/ADT/TrieRawHashMap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/include/llvm/ADT/TrieRawHashMap.h b/llvm/include/llvm/ADT/TrieRawHashMap.h
index 5bfe5c9e6a0f4..e312967edeb58 100644
--- a/llvm/include/llvm/ADT/TrieRawHashMap.h
+++ b/llvm/include/llvm/ADT/TrieRawHashMap.h
@@ -72,7 +72,7 @@ class ThreadSafeTrieRawHashMapBase {
 private:
   template <class T> struct AllocValueType {
     char Base[TrieContentBaseSize];
-    std::aligned_union_t<sizeof(T), T> Content;
+    alignas(T) char Content[sizeof(T)];
   };
 
 protected:

>From 0f1d46a85afd499ddff7189f18605d3c869f4f1a Mon Sep 17 00:00:00 2001
From: Victor Vianna <victor.vianna10 at gmail.com>
Date: Thu, 10 Apr 2025 10:07:54 +0100
Subject: [PATCH 2/2] [cpp23] Remove std::aligned_union in llvm/.../compiler-rt

aligned_union is deprecated in C++23. See more details in the linked bug

Bug: https://crbug.com/388068052
---
 compiler-rt/lib/orc/error.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/orc/error.h b/compiler-rt/lib/orc/error.h
index e64332e9ae764..28035095b692a 100644
--- a/compiler-rt/lib/orc/error.h
+++ b/compiler-rt/lib/orc/error.h
@@ -367,8 +367,8 @@ template <typename T> class ORC_RT_NODISCARD Expected {
   }
 
   union {
-    std::aligned_union_t<1, storage_type> TStorage;
-    std::aligned_union_t<1, error_type> ErrorStorage;
+    alignas(storage_type) char TStorage[sizeof(storage_type)];
+    alignas(error_type) char ErrorStorage[sizeof(error_type)];
   };
 
   bool HasError : 1;



More information about the llvm-commits mailing list