From 73399b053fad107282bbf13616eaf5c3134822b5 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 19 Jun 2025 17:50:15 +0800 Subject: [PATCH] common/static_ptr: avoid using std::aligned_storage_t std::aligned_storage_t was deprecated in C++23, to be prepared for it, let's use alignas for the same behavior. because the size of `Base` class is not always power-of-2, while `alignas()` requires an alignment of power of 2. so we use `std::bit_ceil()` to calculate the minimum alignment greater or equal to its size. Signed-off-by: Kefu Chai --- src/common/static_ptr.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/static_ptr.h b/src/common/static_ptr.h index 31df4cf0a3ca5..af069222cdd9a 100644 --- a/src/common/static_ptr.h +++ b/src/common/static_ptr.h @@ -14,6 +14,7 @@ #pragma once +#include #include #include #include @@ -100,7 +101,9 @@ class static_ptr { // difference in semantics between a pointer-to-const and a const // pointer. // - mutable typename std::aligned_storage::type buf; + mutable struct alignas(std::bit_ceil(Size)) { + unsigned char data[sizeof(Base)]; + } buf; public: using element_type = Base; -- 2.39.5