From: Kefu Chai Date: Tue, 29 Apr 2025 02:54:57 +0000 (+0800) Subject: include/any.h: avoid using std::aligned_storage_t X-Git-Tag: testing/wip-vshankar-testing-20250525.122301-debug~1^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=74644aa8847894baba9672b6073a6ddc25137056;p=ceph-ci.git include/any.h: 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 we do not always pass a power-of-2 number to `immobile_any`, while `alignas()` requires an alignment of power of 2. so we use `std::bit_ceil()` to calculate the minimum alignment greater or equal to the given number. Signed-off-by: Kefu Chai --- diff --git a/src/include/any.h b/src/include/any.h index da59c88f482..88a5fb3f913 100644 --- a/src/include/any.h +++ b/src/include/any.h @@ -16,6 +16,7 @@ #define INCLUDE_STATIC_ANY #include +#include #include #include #include @@ -491,6 +492,11 @@ any_cast(_any::base&& a) { throw std::bad_any_cast(); } + template + struct alignas(Alignment) aligned_storage { + std::byte data[S]; + }; + // `immobile_any` // ============== // @@ -508,12 +514,11 @@ any_cast(_any::base&& a) { // invoked when they throw. // template -class immobile_any : public _any::base, - std::aligned_storage_t> { - using base = _any::base, std::aligned_storage_t>; +class immobile_any : public _any::base, aligned_storage> { + using base = _any::base, aligned_storage>; friend base; - using _any::base, std::aligned_storage_t>::storage; + using _any::base, aligned_storage>::storage; // Superclass requirements! // ------------------------