From a6f35491d69bdf25c8611f1a83b0e087c29c52d8 Mon Sep 17 00:00:00 2001 From: Victor Hugo Vianna Silva Date: Mon, 3 Feb 2025 10:43:14 +0000 Subject: [PATCH] [cpp23] Remove use of std::aligned_storage in webrtc std::aligned_storage is deprecated in C++23, see linked bug. The only webrtc usage (VoidUnion::inline_storage) employed the default Align parameter (i.e. std::aligned_storage, not std::aligned_storage), which is defined as the largest alignment <= Len. This patch replaces the usage with a char buffer of same size and alignment alignof(std::max_align_t). In theory, this might increase alignment and use more memory. In practice, local testing in my machines showed no behavior change, since Len = kInlineStorageWords * sizeof(uintptr_t) = 32 > 16 (maximum alignment on linux x86_64) > 8 (maximum alignment on mac arm64). Bug: chromium:388068052 Change-Id: If08b69f7a5ff7b716a66c8703e31eb5d4de14431 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/373800 Commit-Queue: Victor Vianna Reviewed-by: Mirko Bonadei Auto-Submit: Victor Vianna Reviewed-by: Tomas Gunnarsson Cr-Commit-Position: refs/heads/main@{#43842} --- rtc_base/untyped_function.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rtc_base/untyped_function.h b/rtc_base/untyped_function.h index c1f59458b9..b7e1de1551 100644 --- a/rtc_base/untyped_function.h +++ b/rtc_base/untyped_function.h @@ -30,8 +30,9 @@ enum : size_t { kInlineStorageWords = 4 }; union VoidUnion { void* void_ptr; FunVoid* fun_ptr; - typename std::aligned_storage::type - inline_storage; + // std::max_align_t satisfies alignment requirements for every type. + alignas(std::max_align_t) char inline_storage[kInlineStorageWords * + sizeof(uintptr_t)]; }; // Returns the number of elements of the `inline_storage` array required to