Skip to content

Commit

Permalink
addressed a -Wall warning
Browse files Browse the repository at this point in the history
  • Loading branch information
dietmarkuehl committed Jan 23, 2025
1 parent 556b762 commit ef136b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions include/beman/lazy/detail/allocator_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ struct allocator_support {
}

template <typename... A>
void* operator new(std::size_t size, A&&... a) {
static void* operator new(std::size_t size, A&&... a) {
Allocator alloc{::beman::lazy::detail::find_allocator<Allocator>(a...)};
void* ptr{allocator_traits::allocate(alloc, offset(size) + sizeof(Allocator))};
new (get_allocator(ptr, size)) Allocator(alloc);
void* ptr{allocator_traits::allocate(alloc, allocator_support::offset(size) + sizeof(Allocator))};
new (allocator_support::get_allocator(ptr, size)) Allocator(alloc);
return ptr;
}
void operator delete(void* ptr, std::size_t size) {
Allocator* aptr{get_allocator(ptr, size)};
template <typename... A>
static void operator delete(void* ptr, std::size_t size, A&&...) {
allocator_support::operator delete(ptr, size);
}
static void operator delete(void* ptr, std::size_t size) {
Allocator* aptr{allocator_support::get_allocator(ptr, size)};
Allocator alloc{*aptr};
aptr->~Allocator();
// alloc.deallocate(static_cast<std::byte*>(ptr), offset(size) + sizeof(Allocator));
allocator_traits::deallocate(alloc, static_cast<std::byte*>(ptr), offset(size) + sizeof(Allocator));
allocator_traits::deallocate(
alloc, static_cast<std::byte*>(ptr), allocator_support::offset(size) + sizeof(Allocator));
}
};
} // namespace beman::lazy::detail
Expand Down
2 changes: 1 addition & 1 deletion tests/beman/lazy/allocator_support.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ int main() {
assert(resource.outstanding != 0u);
ptr->~type();
assert(resource.outstanding != 0u);
type::operator delete(ptr, sizeof(type));
type::operator delete(ptr, sizeof(type), std::allocator_arg, &resource);
assert(resource.outstanding == 0u);
}

0 comments on commit ef136b0

Please sign in to comment.