From 216999e552e7f73e63c7bcc88b8ce9c179bbdbe2 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 25 Jun 2023 13:46:53 +0300 Subject: [PATCH] Avoid -Wsign-conversion warning in checked_delete.hpp --- include/boost/core/checked_delete.hpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/include/boost/core/checked_delete.hpp b/include/boost/core/checked_delete.hpp index 6af5c14..b74a43a 100644 --- a/include/boost/core/checked_delete.hpp +++ b/include/boost/core/checked_delete.hpp @@ -30,16 +30,33 @@ namespace boost template inline void checked_delete(T * x) BOOST_NOEXCEPT { - // intentionally complex - simplification causes regressions - typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; +#if defined(__cpp_static_assert) && __cpp_static_assert >= 200410L + + static_assert( sizeof(T) != 0, "Type must be complete" ); + +#else + + typedef char type_must_be_complete[ sizeof(T) ]; (void) sizeof(type_must_be_complete); + +#endif + delete x; } template inline void checked_array_delete(T * x) BOOST_NOEXCEPT { - typedef char type_must_be_complete[ sizeof(T)? 1: -1 ]; +#if defined(__cpp_static_assert) && __cpp_static_assert >= 200410L + + static_assert( sizeof(T) != 0, "Type must be complete" ); + +#else + + typedef char type_must_be_complete[ sizeof(T) ]; (void) sizeof(type_must_be_complete); + +#endif + delete [] x; }