From 67bda76dadfe5128a02b4819b28228caf0940bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sun, 9 Apr 2017 13:44:08 +0200 Subject: [PATCH] Fixed Trac #12920 ("movelib::unique_ptr: incorrect pointer type for nested array") --- doc/move.qbk | 7 +++++++ include/boost/move/default_delete.hpp | 18 +++++++++++++++++- .../move/detail/unique_ptr_meta_utils.hpp | 2 +- test/unique_ptr_types.cpp | 11 +++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/doc/move.qbk b/doc/move.qbk index efb84ec..f380d5b 100644 --- a/doc/move.qbk +++ b/doc/move.qbk @@ -788,6 +788,13 @@ Many thanks to all boosters that have tested, reviewed and improved the library. [section:release_notes Release Notes] +[section:release_notes_boost_1_64 Boost 1.64 Release] + +* Fixed bug: + * [@https://svn.boost.org/trac/boost/ticket/12920 #12920 ['"movelib::unique_ptr: incorrect pointer type for nested array"]]. + +[endsect] + [section:release_notes_boost_1_62 Boost 1.62 Release] * Documented new limitations reported in Trac tickets diff --git a/include/boost/move/default_delete.hpp b/include/boost/move/default_delete.hpp index 1c26ed9..31ae67a 100644 --- a/include/boost/move/default_delete.hpp +++ b/include/boost/move/default_delete.hpp @@ -96,6 +96,22 @@ typedef int bool_conversion::* explicit_bool_arg; typedef int (bool_conversion::*nullptr_type)(); #endif +template +struct is_array_del +{}; + +template +void call_delete(T *p, is_array_del) +{ + delete [] p; +} + +template +void call_delete(T *p, is_array_del) +{ + delete p; +} + } //namespace move_upd { // @endcond @@ -184,7 +200,7 @@ struct default_delete //and T has no virtual destructor, then you have a problem BOOST_STATIC_ASSERT(( !::boost::move_upmu::missing_virtual_destructor::value )); element_type * const p = static_cast(ptr); - bmupmu::is_array::value ? delete [] p : delete p; + move_upd::call_delete(p, move_upd::is_array_del::value>()); } //! Effects: Same as (*this)(static_cast(nullptr)). diff --git a/include/boost/move/detail/unique_ptr_meta_utils.hpp b/include/boost/move/detail/unique_ptr_meta_utils.hpp index 3372068..ac270a8 100644 --- a/include/boost/move/detail/unique_ptr_meta_utils.hpp +++ b/include/boost/move/detail/unique_ptr_meta_utils.hpp @@ -397,7 +397,7 @@ struct pointer_type_imp template struct pointer_type_imp { - typedef typename remove_extent::type* type; + typedef T* type; }; template diff --git a/test/unique_ptr_types.cpp b/test/unique_ptr_types.cpp index 799b417..7dbc0c3 100644 --- a/test/unique_ptr_types.cpp +++ b/test/unique_ptr_types.cpp @@ -75,6 +75,17 @@ void test() typedef bml::unique_ptr P; BOOST_STATIC_ASSERT((bmupmu::is_same::value)); } + //Unbounded array of bounded array unique_ptr + { + typedef int int_5_t [5]; + typedef bml::unique_ptr P; + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); + } + { + typedef int int_5_t [5]; + typedef bml::unique_ptr P; + BOOST_STATIC_ASSERT((bmupmu::is_same::value)); + } } } //namespace unique_ptr_pointer_type {