From 91eddbabe8978baf5b46c951f6cffa343d9aec55 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Mon, 12 Dec 2022 11:26:12 +0100 Subject: [PATCH] restricted memcpy to allocators known to not have fancy construct() --- include/boost/unordered/detail/foa.hpp | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 0ef15ef1..ccf48227 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1025,6 +1026,47 @@ inline void prefetch(const void* p) struct try_emplace_args_t{}; +template +struct is_std_allocator:std::false_type{}; + +template +struct is_std_allocator>:std::true_type{}; + +/* std::allocator::construct marked as deprecated */ +#if defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH) +_LIBCPP_SUPPRESS_DEPRECATED_PUSH +#elif defined(_STL_DISABLE_DEPRECATED_WARNING) +_STL_DISABLE_DEPRECATED_WARNING +#elif defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4996) +#endif + +template +struct alloc_has_construct +{ +private: + template + static decltype( + std::declval().construct( + std::declval(),std::declval()...), + std::true_type{} + ) check(int); + + template static std::false_type check(...); + +public: + static constexpr bool value=decltype(check(0))::value; +}; + +#if defined(_LIBCPP_SUPPRESS_DEPRECATED_POP) +_LIBCPP_SUPPRESS_DEPRECATED_POP +#elif defined(_STL_RESTORE_DEPRECATED_WARNING) +_STL_RESTORE_DEPRECATED_WARNING +#elif defined(_MSC_VER) +#pragma warning(pop) +#endif + #if defined(BOOST_GCC) /* GCC's -Wshadow triggers at scenarios like this: * @@ -1590,6 +1632,9 @@ private: #else std::is_trivially_copy_constructible::value #endif + &&( + is_std_allocator::value|| + !alloc_has_construct::value) >{} ); }