mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[upstream_utils] Fix LLVM's AlignedCharArrayUnion for C++23 (#6830)
C++23 deprecated std::aligned_union_t.
This commit is contained in:
@@ -13,20 +13,16 @@
|
||||
#ifndef WPIUTIL_WPI_ALIGNOF_H
|
||||
#define WPIUTIL_WPI_ALIGNOF_H
|
||||
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
|
||||
namespace wpi {
|
||||
|
||||
/// A suitably aligned and sized character array member which can hold elements
|
||||
/// of any type.
|
||||
///
|
||||
/// This template is equivalent to std::aligned_union_t<1, ...>, but we cannot
|
||||
/// use it due to a bug in the MSVC x86 compiler:
|
||||
/// https://github.com/microsoft/STL/issues/1533
|
||||
/// Using `alignas` here works around the bug.
|
||||
template <typename T, typename... Ts> struct AlignedCharArrayUnion {
|
||||
using AlignedUnion = std::aligned_union_t<1, T, Ts...>;
|
||||
alignas(alignof(AlignedUnion)) char buffer[sizeof(AlignedUnion)];
|
||||
template <typename... Ts> struct AlignedCharArrayUnion {
|
||||
alignas((std::max)({alignof(Ts)...}))
|
||||
std::byte buffer[(std::max)({static_cast<size_t>(1), sizeof(Ts)...})];
|
||||
};
|
||||
|
||||
} // end namespace wpi
|
||||
|
||||
Reference in New Issue
Block a user