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
This commit is contained in:
Christian Mazakas
2023-09-20 13:13:49 -07:00
parent 777f2084a3
commit 423eb08f00
2 changed files with 4 additions and 4 deletions

View File

@@ -35,8 +35,8 @@ template <typename T> struct test_allocator
typedef T value_type; typedef T value_type;
test_allocator() = default; test_allocator() = default;
template <typename T2> test_allocator(test_allocator<T2> const&) {} template <typename T2> test_allocator(test_allocator<T2> const&) {}
T* allocate(std::size_t n) const { return (T*)malloc(sizeof(T) * n); } T* allocate(std::size_t n) const { return (T*)(::operator new(sizeof(T) * n)); }
void deallocate(T* ptr, std::size_t) const { free(ptr); } 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 true; }
bool operator!=(test_allocator const&) const { return false; } bool operator!=(test_allocator const&) const { return false; }
}; };

View File

@@ -30,13 +30,13 @@ template <typename T> struct A
{ {
total_allocation += n * sizeof(T); total_allocation += n * sizeof(T);
++num_allocations; ++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 void deallocate(T* p, std::size_t n) noexcept
{ {
total_allocation -= n * sizeof(T); total_allocation -= n * sizeof(T);
std::free(p); ::operator delete(p);
} }
bool operator==(A const& a) const { return i == a.i; } bool operator==(A const& a) const { return i == a.i; }