From: Kefu Chai Date: Thu, 19 Jun 2025 09:50:15 +0000 (+0800) Subject: common/static_ptr: avoid using std::aligned_storage_t X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=73399b053fad107282bbf13616eaf5c3134822b5;p=ceph.git 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 --- 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;