[ox] Fix for a broken new memory safety check in GCC13

This commit is contained in:
Gary Talent 2023-05-19 21:30:51 -05:00
parent f63fe6c995
commit fcf0a9be95

View File

@ -26,6 +26,8 @@ namespace detail {
template<typename T, typename Allocator, std::size_t Size = 1>
struct VectorAllocator {
static_assert(sizeof(AllocAlias<T>) == sizeof(T));
static_assert(alignof(AllocAlias<T>) == alignof(T));
private:
ox::Array<AllocAlias<T>, Size> m_data = {};
Allocator m_allocator;
@ -46,11 +48,11 @@ struct VectorAllocator {
constexpr void moveConstructItemsFrom(T **items, VectorAllocator *src, const std::size_t count, const std::size_t cap) noexcept {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later
if (cap <= Size && count <= Size) {
const auto dstItems = reinterpret_cast<T*>(m_data.data());
const auto srcItems = reinterpret_cast<T*>(src->m_data.data());
if (cap <= m_data.size() && count <= m_data.size()) {
for (auto i = 0u; i < count; ++i) {
std::construct_at<T>(&dstItems[i], std::move(srcItems[i]));
const auto dstItem = reinterpret_cast<T*>(&m_data[i]);
const auto srcItem = reinterpret_cast<T*>(&src->m_data[i]);
std::construct_at<T>(dstItem, std::move(*srcItem));
}
*items = reinterpret_cast<T*>(m_data.data());
}
@ -59,11 +61,11 @@ struct VectorAllocator {
constexpr void moveItemsFrom(T **items, VectorAllocator *src, const std::size_t count, const std::size_t cap) noexcept {
// this totally idiotic redundant check (&& count <= Size) is required to address a bug in devkitARM,
// try removing it later
if (cap <= Size && count <= Size) {
const auto dstItems = reinterpret_cast<T*>(m_data.data());
const auto srcItems = reinterpret_cast<T*>(src->m_data.data());
if (cap <= m_data.size() && count <= m_data.size()) {
for (std::size_t i = 0; i < count; ++i) {
dstItems[i] = std::move(srcItems[i]);
const auto dstItem = reinterpret_cast<T*>(&m_data[i]);
const auto srcItem = reinterpret_cast<T*>(&src->m_data[i]);
*dstItem = std::move(*srcItem);
}
*items = reinterpret_cast<T*>(m_data.data());
}