From f7bcf9a3dd7ea10e61ebe8af01415928207d5152 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 20 Sep 2023 13:13:49 -0700 Subject: [PATCH] Work around bugs in gcc's analysis Under `-m32 -O3` builds, it seems like gcc gets confused by the usage of malloc and calloc so we opt into the C++ versions, operator new and delete --- test/unordered/deduction_tests.cpp | 4 ++-- test/unordered/reserve_tests.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unordered/deduction_tests.cpp b/test/unordered/deduction_tests.cpp index 571aa7fa..7d3996e3 100644 --- a/test/unordered/deduction_tests.cpp +++ b/test/unordered/deduction_tests.cpp @@ -35,8 +35,8 @@ template struct test_allocator typedef T value_type; test_allocator() = default; template test_allocator(test_allocator const&) {} - T* allocate(std::size_t n) const { return (T*)malloc(sizeof(T) * n); } - void deallocate(T* ptr, std::size_t) const { free(ptr); } + T* allocate(std::size_t n) const { return (T*)(::operator new(sizeof(T) * n)); } + void deallocate(T* ptr, std::size_t) const { ::operator delete(ptr); } bool operator==(test_allocator const&) const { return true; } bool operator!=(test_allocator const&) const { return false; } }; diff --git a/test/unordered/reserve_tests.cpp b/test/unordered/reserve_tests.cpp index 29b4b5b0..7ef0c5c4 100644 --- a/test/unordered/reserve_tests.cpp +++ b/test/unordered/reserve_tests.cpp @@ -30,13 +30,13 @@ template struct A { total_allocation += n * sizeof(T); ++num_allocations; - return (T*)std::calloc(n, sizeof(T)); + return (T*)(::operator new(n * sizeof(T))); } void deallocate(T* p, std::size_t n) noexcept { total_allocation -= n * sizeof(T); - std::free(p); + ::operator delete(p); } bool operator==(A const& a) const { return i == a.i; }