From b8c59d595c099f1bf4eb9440b31f6b5a12880614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 16 Jul 2022 20:55:42 +0200 Subject: [PATCH] Fixes #210: ("Use sized delete in boost::container::new_allocator...") --- doc/container.qbk | 1 + include/boost/container/detail/placement_new.hpp | 2 ++ include/boost/container/new_allocator.hpp | 11 +++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/container.qbk b/doc/container.qbk index e5d6f57..1dd3139 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1342,6 +1342,7 @@ use [*Boost.Container]? There are several reasons for that: * Fixed bugs/issues: * [@https://github.com/boostorg/container/issues/209 GitHub #209: ['"Some boost warnings with my R package (Wclass-memaccess warnings with std::pair)"]]. + * [@https://github.com/boostorg/container/issues/210 GitHub #210: ['"Use sized delete in boost::container::new_allocator if __cpp_sized_deallocation is defined"]]. * [@https://github.com/boostorg/container/issues/221 GitHub #218: ['"small_vector static capacity is too small when not a multiple of 8 bytes"]]. * [@https://github.com/boostorg/container/issues/221 GitHub #221: ['"flat_set and friends should offer a const sequence_type& sequence() const method (...)"]]. * [@https://github.com/boostorg/container/pull/222 GitHub #222: ['"Fix incomplete type error when using list with pair"]]. diff --git a/include/boost/container/detail/placement_new.hpp b/include/boost/container/detail/placement_new.hpp index c50981f..73db6c1 100644 --- a/include/boost/container/detail/placement_new.hpp +++ b/include/boost/container/detail/placement_new.hpp @@ -18,6 +18,8 @@ # pragma once #endif +#include + struct boost_container_new_t{}; //avoid including diff --git a/include/boost/container/new_allocator.hpp b/include/boost/container/new_allocator.hpp index 2fad21a..82c42a9 100644 --- a/include/boost/container/new_allocator.hpp +++ b/include/boost/container/new_allocator.hpp @@ -162,8 +162,15 @@ class new_allocator //!Deallocates previously allocated memory. //!Never throws - void deallocate(pointer ptr, size_type) BOOST_NOEXCEPT_OR_NOTHROW - { ::operator delete((void*)ptr); } + void deallocate(pointer ptr, size_type n) BOOST_NOEXCEPT_OR_NOTHROW + { + (void)n; + # if __cpp_sized_deallocation + ::operator delete((void*)ptr, n * sizeof(T)); + #else + ::operator delete((void*)ptr); + # endif + } //!Returns the maximum number of elements that could be allocated. //!Never throws