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.
This commit is contained in:
Danny Robson 2024-08-06 14:44:47 +10:00
parent e43535c2a7
commit a73db2a75c
2 changed files with 10 additions and 6 deletions

View File

@ -107,9 +107,9 @@ namespace cruft {
> >
T readhe (u08 const *data) T readhe (u08 const *data)
{ {
std::aligned_union_t <sizeof (T), T> buffer; T value;
memcpy (reinterpret_cast<char *> (&buffer), data, sizeof (T)); memcpy (&value, data, sizeof (T));
return *reinterpret_cast<const T*> (&buffer); return value;
} }

View File

@ -931,10 +931,14 @@ namespace cruft {
if (unlikely (sizeof (ValueT) > buffer.size () * sizeof (WordT))) if (unlikely (sizeof (ValueT) > buffer.size () * sizeof (WordT)))
throw std::runtime_error ("insufficient data for extraction"); throw std::runtime_error ("insufficient data for extraction");
std::aligned_storage_t<sizeof(ValueT),alignof(ValueT)> bytes; WordT* const head = buffer.begin ();
memcpy (&bytes, buffer.data (), sizeof (ValueT));
buffer = buffer.consume (sizeof (ValueT) / sizeof (WordT)); buffer = buffer.consume (sizeof (ValueT) / sizeof (WordT));
return *reinterpret_cast<ValueT const*> (&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;
} }