[C++] Stop using std::aligned_storage. (#34110)

Indeed this is now deprecated since C++23.

Fix #32848.
pull/34329/head
Romain Geissler @ Amadeus 1 year ago committed by GitHub
parent ab806f4219
commit d0d826750f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      include/grpcpp/server_context.h
  2. 3
      src/core/lib/gprpp/manual_constructor.h
  3. 2
      src/core/lib/gprpp/no_destruct.h
  4. 6
      src/core/lib/iomgr/event_engine_shims/endpoint.cc
  5. 6
      src/core/lib/promise/arena_promise.h
  6. 4
      test/core/gprpp/ref_counted_test.cc

@ -545,8 +545,7 @@ class ServerContextBase {
const std::function<void(grpc::Status s)> func_; const std::function<void(grpc::Status s)> func_;
}; };
typename std::aligned_storage<sizeof(Reactor), alignof(Reactor)>::type alignas(Reactor) char default_reactor_[sizeof(Reactor)];
default_reactor_;
std::atomic_bool default_reactor_used_{false}; std::atomic_bool default_reactor_used_{false};
std::atomic_bool marked_cancelled_{false}; std::atomic_bool marked_cancelled_{false};

@ -25,7 +25,6 @@
#include <stddef.h> #include <stddef.h>
#include <type_traits>
#include <utility> #include <utility>
#include "src/core/lib/gprpp/construct_destruct.h" #include "src/core/lib/gprpp/construct_destruct.h"
@ -139,7 +138,7 @@ class ManualConstructor {
void Destroy() { Destruct(get()); } void Destroy() { Destruct(get()); }
private: private:
typename std::aligned_storage<sizeof(Type), alignof(Type)>::type space_; alignas(Type) char space_[sizeof(Type)];
}; };
} // namespace grpc_core } // namespace grpc_core

@ -68,7 +68,7 @@ class NoDestruct {
const T* get() const { return reinterpret_cast<const T*>(&space_); } const T* get() const { return reinterpret_cast<const T*>(&space_); }
private: private:
typename std::aligned_storage<sizeof(T), alignof(T)>::type space_; alignas(T) char space_[sizeof(T)];
}; };
// Helper for when a program desires a single *process wide* instance of a // Helper for when a program desires a single *process wide* instance of a

@ -60,10 +60,8 @@ class EventEngineEndpointWrapper {
struct grpc_event_engine_endpoint { struct grpc_event_engine_endpoint {
grpc_endpoint base; grpc_endpoint base;
EventEngineEndpointWrapper* wrapper; EventEngineEndpointWrapper* wrapper;
std::aligned_storage<sizeof(SliceBuffer), alignof(SliceBuffer)>::type alignas(SliceBuffer) char read_buffer[sizeof(SliceBuffer)];
read_buffer; alignas(SliceBuffer) char write_buffer[sizeof(SliceBuffer)];
std::aligned_storage<sizeof(SliceBuffer), alignof(SliceBuffer)>::type
write_buffer;
}; };
explicit EventEngineEndpointWrapper( explicit EventEngineEndpointWrapper(

@ -19,6 +19,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <cstddef>
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
@ -34,7 +35,10 @@ namespace grpc_core {
namespace arena_promise_detail { namespace arena_promise_detail {
using ArgType = std::aligned_storage_t<sizeof(void*)>; struct ArgType {
alignas(std::max_align_t) char buffer[sizeof(void*)];
};
template <typename T> template <typename T>
T*& ArgAsPtr(ArgType* arg) { T*& ArgAsPtr(ArgType* arg) {
static_assert(sizeof(ArgType) >= sizeof(T**), static_assert(sizeof(ArgType) >= sizeof(T**),

@ -119,8 +119,8 @@ class ValueInExternalAllocation
}; };
TEST(RefCounted, CallDtorUponUnref) { TEST(RefCounted, CallDtorUponUnref) {
std::aligned_storage<sizeof(ValueInExternalAllocation), alignas(ValueInExternalAllocation) char
alignof(ValueInExternalAllocation)>::type storage; storage[sizeof(ValueInExternalAllocation)];
RefCountedPtr<ValueInExternalAllocation> value( RefCountedPtr<ValueInExternalAllocation> value(
new (&storage) ValueInExternalAllocation(5)); new (&storage) ValueInExternalAllocation(5));
EXPECT_EQ(value->value(), 5); EXPECT_EQ(value->value(), 5);

Loading…
Cancel
Save