diff --git a/connections/implementation/analytics/throughput_recorder.cc b/connections/implementation/analytics/throughput_recorder.cc index 62d7ac21..54b31d05 100644 --- a/connections/implementation/analytics/throughput_recorder.cc +++ b/connections/implementation/analytics/throughput_recorder.cc @@ -43,9 +43,8 @@ ThroughputRecorder::ThroughputRecorder(int64_t payload_id) : payload_id_(payload_id) {} ThroughputRecorderContainer& ThroughputRecorderContainer::GetInstance() { - static std::aligned_storage_t - storage; + alignas(ThroughputRecorderContainer) static char + storage[sizeof(ThroughputRecorderContainer)]; static ThroughputRecorderContainer* env = new (&storage) ThroughputRecorderContainer(); return *env; diff --git a/connections/implementation/mediums/multiplex/multiplex_socket.cc b/connections/implementation/mediums/multiplex/multiplex_socket.cc index cb338946..cd9ea191 100644 --- a/connections/implementation/mediums/multiplex/multiplex_socket.cc +++ b/connections/implementation/mediums/multiplex/multiplex_socket.cc @@ -95,17 +95,10 @@ MultiplexSocket::MultiplexSocket(std::shared_ptr physical_socket) absl::flat_hash_map, MultiplexIncomingConnectionCb>& MultiplexSocket::GetIncomingConnectionCallbacks() { - static std::aligned_storage_t< - sizeof(absl::flat_hash_map, - MultiplexIncomingConnectionCb>), - alignof(absl::flat_hash_map, - MultiplexIncomingConnectionCb>)> - storage; - static absl::flat_hash_map, - MultiplexIncomingConnectionCb>* - incoming_connection_callbacks = - new (&storage) absl::flat_hash_map, - MultiplexIncomingConnectionCb>(); + using MapType = absl::flat_hash_map, + MultiplexIncomingConnectionCb>; + alignas(MapType) static char storage[sizeof(MapType)]; + static MapType* incoming_connection_callbacks = new (&storage) MapType(); return *incoming_connection_callbacks; } @@ -121,23 +114,18 @@ MultiplexSocket* MultiplexSocket::CreateIncomingSocket( static MultiplexSocket* multiplex_incoming_socket = nullptr; switch (physical_socket->GetMedium()) { case Medium::BLUETOOTH: - static std::aligned_storage_t - storage_bt; + alignas(MultiplexSocket) static char storage_bt[sizeof(MultiplexSocket)]; multiplex_incoming_socket = new (&storage_bt) MultiplexSocket(physical_socket); break; case Medium::BLE: - static std::aligned_storage_t - storage_ble; + alignas(MultiplexSocket) static char storage_ble[sizeof(MultiplexSocket)]; multiplex_incoming_socket = new (&storage_ble) MultiplexSocket(physical_socket); break; case Medium::WIFI_LAN: - static std::aligned_storage_t - storage_wlan; + alignas( + MultiplexSocket) static char storage_wlan[sizeof(MultiplexSocket)]; multiplex_incoming_socket = new (&storage_wlan) MultiplexSocket(physical_socket); break; @@ -169,23 +157,18 @@ MultiplexSocket* MultiplexSocket::CreateOutgoingSocket( static MultiplexSocket* multiplex_outgoing_socket = nullptr; switch (physical_socket->GetMedium()) { case Medium::BLUETOOTH: - static std::aligned_storage_t - storage_bt; + alignas(MultiplexSocket) static char storage_bt[sizeof(MultiplexSocket)]; multiplex_outgoing_socket = new (&storage_bt) MultiplexSocket(physical_socket); break; case Medium::BLE: - static std::aligned_storage_t - storage_ble; + alignas(MultiplexSocket) static char storage_ble[sizeof(MultiplexSocket)]; multiplex_outgoing_socket = new (&storage_ble) MultiplexSocket(physical_socket); break; case Medium::WIFI_LAN: - static std::aligned_storage_t - storage_wlan; + alignas( + MultiplexSocket) static char storage_wlan[sizeof(MultiplexSocket)]; multiplex_outgoing_socket = new (&storage_wlan) MultiplexSocket(physical_socket); break; diff --git a/internal/platform/implementation/windows/wifi_intel.cc b/internal/platform/implementation/windows/wifi_intel.cc index 737dfc01..20daf8c0 100644 --- a/internal/platform/implementation/windows/wifi_intel.cc +++ b/internal/platform/implementation/windows/wifi_intel.cc @@ -137,7 +137,7 @@ MurocDefs::INTEL_CALLBACK g_intel_event_cb_handle = {IntelEventHandler, #endif WifiIntel& WifiIntel::GetInstance() { - static std::aligned_storage_t storage; + alignas(WifiIntel) static char storage[sizeof(WifiIntel)]; static WifiIntel* instance = new (&storage) WifiIntel(); return *instance; } diff --git a/internal/platform/medium_environment.cc b/internal/platform/medium_environment.cc index 885a7a22..14518655 100644 --- a/internal/platform/medium_environment.cc +++ b/internal/platform/medium_environment.cc @@ -52,9 +52,7 @@ namespace nearby { MediumEnvironment& MediumEnvironment::Instance() { - static std::aligned_storage_t - storage; + alignas(MediumEnvironment) static char storage[sizeof(MediumEnvironment)]; static MediumEnvironment* env = new (&storage) MediumEnvironment(); return *env; }