Skip to content

Commit

Permalink
fixed a problem with using delete after placement new
Browse files Browse the repository at this point in the history
  • Loading branch information
dietmarkuehl committed Jan 23, 2025
1 parent 037af46 commit 556b762
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tests/beman/lazy/allocator_support.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ struct allocator_aware : some_data, beman::lazy::detail::allocator_support<Alloc
} // namespace

int main() {
delete new allocator_aware<std::pmr::polymorphic_allocator<std::byte>>{};
delete new (std::allocator_arg, std::pmr::polymorphic_allocator<std::byte>{})
allocator_aware<std::pmr::polymorphic_allocator<std::byte>>{};
using type = allocator_aware<std::pmr::polymorphic_allocator<std::byte>>;
std::unique_ptr<type>(new type{});

test_resource resource{};
assert(resource.outstanding == 0u);
auto ptr{new (std::allocator_arg, &resource)
allocator_aware<std::pmr::polymorphic_allocator<std::byte>>()};
type* ptr{new (std::allocator_arg, &resource) type{}};
assert(resource.outstanding != 0u);
delete ptr;
ptr->~type();
assert(resource.outstanding != 0u);
type::operator delete(ptr, sizeof(type));
assert(resource.outstanding == 0u);
}

0 comments on commit 556b762

Please sign in to comment.