From 417be15231cb34a2e858d26b63406d1fb5535cb9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 2 Mar 2023 15:38:15 +0200 Subject: Replace deprecated std::aligned_storage with alignas Based on patch by Matthew Krupcale. --- libbuild2/function.hxx | 9 +++++---- libbuild2/scheduler.hxx | 5 +++-- libbuild2/target.hxx | 8 ++++---- libbuild2/variable.cxx | 10 +++++----- libbuild2/variable.hxx | 7 ++++--- 5 files changed, 21 insertions(+), 18 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/function.hxx b/libbuild2/function.hxx index 323ac41..cda856a 100644 --- a/libbuild2/function.hxx +++ b/libbuild2/function.hxx @@ -4,8 +4,9 @@ #ifndef LIBBUILD2_FUNCTION_HXX #define LIBBUILD2_FUNCTION_HXX -#include // index_sequence -#include // aligned_storage +#include // max_align_t +#include // index_sequence +#include // is_* #include #include @@ -133,8 +134,8 @@ namespace build2 // Auxiliary data storage. Note that it is expected to be trivially // copyable and destructible. // - std::aligned_storage::type data; - static const size_t data_size = sizeof (decltype (data)); + static const size_t data_size = sizeof (void*) * 3; + alignas (std::max_align_t) unsigned char data[data_size]; function_overload (const char* an, size_t mi, size_t ma, types ts, diff --git a/libbuild2/scheduler.hxx b/libbuild2/scheduler.hxx index c34d41b..b579d80 100644 --- a/libbuild2/scheduler.hxx +++ b/libbuild2/scheduler.hxx @@ -7,7 +7,8 @@ #include #include #include -#include // aligned_storage, etc +#include // max_align_t +#include // decay, etc #include #include @@ -681,7 +682,7 @@ namespace build2 // struct task_data { - std::aligned_storage::type data; + alignas (std::max_align_t) unsigned char data[sizeof (void*) * 8]; void (*thunk) (scheduler&, lock&, void*); }; diff --git a/libbuild2/target.hxx b/libbuild2/target.hxx index 26c7208..037b18c 100644 --- a/libbuild2/target.hxx +++ b/libbuild2/target.hxx @@ -4,8 +4,9 @@ #ifndef LIBBUILD2_TARGET_HXX #define LIBBUILD2_TARGET_HXX +#include // max_align_t #include // tags, etc. -#include // aligned_storage +#include // is_* #include #include // map_iterator_adapter @@ -189,7 +190,7 @@ namespace build2 ? sizeof (string) : sizeof (void*) * 4); - std::aligned_storage::type data_; + alignas (std::max_align_t) unsigned char data_[data_size]; void (*data_dtor_) (void*) = nullptr; template ::type m_; + alignas (value_type) mutable unsigned char m_[sizeof (value_type)]; }; iterator diff --git a/libbuild2/variable.cxx b/libbuild2/variable.cxx index 260d664..d55737b 100644 --- a/libbuild2/variable.cxx +++ b/libbuild2/variable.cxx @@ -3,7 +3,7 @@ #include -#include // memcmp() +#include // memcmp(), memcpy() #include @@ -57,7 +57,7 @@ namespace build2 else if (type->copy_ctor != nullptr) type->copy_ctor (*this, v, true); else - data_ = v.data_; // Copy as POD. + memcpy (data_, v.data_, size_); // Copy as POD. } } @@ -72,7 +72,7 @@ namespace build2 else if (type->copy_ctor != nullptr) type->copy_ctor (*this, v, false); else - data_ = v.data_; // Copy as POD. + memcpy (data_, v.data_, size_); // Copy as POD. } } @@ -106,7 +106,7 @@ namespace build2 else if (auto f = null ? type->copy_ctor : type->copy_assign) f (*this, v, true); else - data_ = v.data_; // Assign as POD. + memcpy (data_, v.data_, size_); // Assign as POD. null = v.null; } @@ -145,7 +145,7 @@ namespace build2 else if (auto f = null ? type->copy_ctor : type->copy_assign) f (*this, v, false); else - data_ = v.data_; // Assign as POD. + memcpy (data_, v.data_, size_); // Assign as POD. null = v.null; } diff --git a/libbuild2/variable.hxx b/libbuild2/variable.hxx index 8a0adf8..b137789 100644 --- a/libbuild2/variable.hxx +++ b/libbuild2/variable.hxx @@ -4,7 +4,8 @@ #ifndef LIBBUILD2_VARIABLE_HXX #define LIBBUILD2_VARIABLE_HXX -#include // aligned_storage +#include // max_align_t +#include // is_* #include #include @@ -423,8 +424,8 @@ namespace build2 // specialization below). Types that don't fit will have to be handled // with an extra dynamic allocation. // - static constexpr size_t size_ = sizeof (name_pair); - std::aligned_storage::type data_; + static constexpr size_t size_ = sizeof (name_pair); + alignas (std::max_align_t) unsigned char data_[size_]; // Make sure we have sufficient storage for untyped values. // -- cgit v1.1