]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/static_ptr: avoid using std::aligned_storage_t 64040/head
authorKefu Chai <tchaikov@gmail.com>
Thu, 19 Jun 2025 09:50:15 +0000 (17:50 +0800)
committerKefu Chai <tchaikov@gmail.com>
Thu, 19 Jun 2025 09:53:04 +0000 (17:53 +0800)
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 <tchaikov@gmail.com>
src/common/static_ptr.h

index 31df4cf0a3ca58eb3cd501be52a55f01054ac368..af069222cdd9ab7b6a8a6cbf6f0a39ffde52b248 100644 (file)
@@ -14,6 +14,7 @@
 
 #pragma once
 
+#include <bit>
 #include <cstddef>
 #include <utility>
 #include <type_traits>
@@ -100,7 +101,9 @@ class static_ptr {
   // difference in semantics between a pointer-to-const and a const
   // pointer.
   //
-  mutable typename std::aligned_storage<Size>::type buf;
+  mutable struct alignas(std::bit_ceil(Size)) {
+    unsigned char data[sizeof(Base)];
+  } buf;
 
 public:
   using element_type = Base;