]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
include/any.h: avoid using std::aligned_storage_t
authorKefu Chai <tchaikov@gmail.com>
Tue, 29 Apr 2025 02:54:57 +0000 (10:54 +0800)
committerKefu Chai <tchaikov@gmail.com>
Tue, 29 Apr 2025 07:25:58 +0000 (15:25 +0800)
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 <tchaikov@gmail.com>
src/include/any.h

index da59c88f482dcd05365baa936d915ee2703ca7bc..88a5fb3f913e4a16ad2ae7098b12b3f4efa6b4df 100644 (file)
@@ -16,6 +16,7 @@
 #define INCLUDE_STATIC_ANY
 
 #include <any>
+#include <bit>
 #include <cstddef>
 #include <initializer_list>
 #include <memory>
@@ -491,6 +492,11 @@ any_cast(_any::base<U, V>&& a) {
   throw std::bad_any_cast();
 }
 
+ template<std::size_t S, std::size_t Alignment = std::bit_ceil(S)>
+ struct alignas(Alignment) aligned_storage {
+   std::byte data[S];
+ };
+
 // `immobile_any`
 // ==============
 //
@@ -508,12 +514,11 @@ any_cast(_any::base<U, V>&& a) {
 // invoked when they throw.
 //
 template<std::size_t S>
-class immobile_any : public _any::base<immobile_any<S>,
-                                      std::aligned_storage_t<S>> {
-  using base = _any::base<immobile_any<S>, std::aligned_storage_t<S>>;
+class immobile_any : public _any::base<immobile_any<S>, aligned_storage<S>> {
+  using base = _any::base<immobile_any<S>, aligned_storage<S>>;
   friend base;
 
-  using _any::base<immobile_any<S>, std::aligned_storage_t<S>>::storage;
+  using _any::base<immobile_any<S>, aligned_storage<S>>::storage;
 
   // Superclass requirements!
   // ------------------------