aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2023-03-02 15:38:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2023-03-02 15:38:15 +0200
commit417be15231cb34a2e858d26b63406d1fb5535cb9 (patch)
tree12c8feacfac7b108405d26cf88ba19284df346c6
parent343d6e69e412166cfc21f268a51b692cb0201653 (diff)
Replace deprecated std::aligned_storage with alignas
Based on patch by Matthew Krupcale.
-rw-r--r--libbuild2/function.hxx9
-rw-r--r--libbuild2/scheduler.hxx5
-rw-r--r--libbuild2/target.hxx8
-rw-r--r--libbuild2/variable.cxx10
-rw-r--r--libbuild2/variable.hxx7
5 files changed, 21 insertions, 18 deletions
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 <utility> // index_sequence
-#include <type_traits> // aligned_storage
+#include <cstddef> // max_align_t
+#include <utility> // index_sequence
+#include <type_traits> // is_*
#include <libbuild2/types.hxx>
#include <libbuild2/forward.hxx>
@@ -133,8 +134,8 @@ namespace build2
// Auxiliary data storage. Note that it is expected to be trivially
// copyable and destructible.
//
- std::aligned_storage<sizeof (void*) * 3>::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 <list>
#include <tuple>
#include <atomic>
-#include <type_traits> // aligned_storage, etc
+#include <cstddef> // max_align_t
+#include <type_traits> // decay, etc
#include <libbuild2/types.hxx>
#include <libbuild2/utility.hxx>
@@ -681,7 +682,7 @@ namespace build2
//
struct task_data
{
- std::aligned_storage<sizeof (void*) * 8>::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 <cstddef> // max_align_t
#include <iterator> // tags, etc.
-#include <type_traits> // aligned_storage
+#include <type_traits> // is_*
#include <unordered_map>
#include <libbutl/multi-index.hxx> // map_iterator_adapter
@@ -189,7 +190,7 @@ namespace build2
? sizeof (string)
: sizeof (void*) * 4);
- std::aligned_storage<data_size>::type data_;
+ alignas (std::max_align_t) unsigned char data_[data_size];
void (*data_dtor_) (void*) = nullptr;
template <typename R,
@@ -1624,8 +1625,7 @@ namespace build2
group_view g_;
size_t j_; // 1-based index, to support enter_group().
const target* k_; // Current member of ad hoc group or NULL.
- mutable typename std::aligned_storage<sizeof (value_type),
- alignof (value_type)>::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 <libbuild2/variable.hxx>
-#include <cstring> // memcmp()
+#include <cstring> // memcmp(), memcpy()
#include <libbutl/path-pattern.hxx>
@@ -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 <type_traits> // aligned_storage
+#include <cstddef> // max_align_t
+#include <type_traits> // is_*
#include <unordered_map>
#include <libbutl/prefix-map.hxx>
@@ -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<size_>::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.
//