From a73db2a75cbe7c7f58744c43cc71275e7d5628e0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 6 Aug 2024 14:44:47 +1000 Subject: [PATCH] build: convert aligned_storage_t to memcpy for small types aligend_storage_t is deprecated in clang-19 and no longer compiles cleanly (generates a warning). These locations don't benefit from any fancy schemes, so just memcpy to a local var and return. --- cruft/util/endian.hpp | 6 +++--- cruft/util/view.hpp | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cruft/util/endian.hpp b/cruft/util/endian.hpp index e2de1f2b..b6de5abf 100644 --- a/cruft/util/endian.hpp +++ b/cruft/util/endian.hpp @@ -107,9 +107,9 @@ namespace cruft { > T readhe (u08 const *data) { - std::aligned_union_t buffer; - memcpy (reinterpret_cast (&buffer), data, sizeof (T)); - return *reinterpret_cast (&buffer); + T value; + memcpy (&value, data, sizeof (T)); + return value; } diff --git a/cruft/util/view.hpp b/cruft/util/view.hpp index 62405622..3140ff75 100644 --- a/cruft/util/view.hpp +++ b/cruft/util/view.hpp @@ -931,10 +931,14 @@ namespace cruft { if (unlikely (sizeof (ValueT) > buffer.size () * sizeof (WordT))) throw std::runtime_error ("insufficient data for extraction"); - std::aligned_storage_t bytes; - memcpy (&bytes, buffer.data (), sizeof (ValueT)); + WordT* const head = buffer.begin (); buffer = buffer.consume (sizeof (ValueT) / sizeof (WordT)); - return *reinterpret_cast (&bytes); + + // Don't use reinterpret_cast or other pointer schemes because it's quite easy to run into alignment issues. + // No one should really be using this for bulk reads anyway, so it shouldn't be a performance issue. + ValueT out; + memcpy (&out, head, sizeof (ValueT)); + return out; }