From c898a3b6532fdf5bc4e2f693f1ce08103333266d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Mart=C3=ADn?= Date: Wed, 3 Jul 2024 11:25:22 +0200 Subject: [PATCH] Virtual destructor check and unique move into lent protection --- include/tl/ptr.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/tl/ptr.h b/include/tl/ptr.h index dd2db49..237f8f3 100644 --- a/include/tl/ptr.h +++ b/include/tl/ptr.h @@ -25,10 +25,24 @@ template class lent_ptr; template using delete_callback = eastl::function; + +template +struct ptr_traits_passes_virtual_destructor_check +{ + static constexpr inline bool value = !std::is_polymorphic::value || std::is_final::value || std::has_virtual_destructor::value; +}; + +template +struct ptr_traits_passes_virtual_destructor_check // check not required +{ + static constexpr inline bool value = true; +}; + template struct ptr_traits { static constexpr inline bool custom_deleter = false; + static constexpr inline bool requires_virtual_destructor_check = true; }; namespace detail @@ -243,6 +257,8 @@ public: { m_del.destroy(m_ptr); CB_UNIQUE_DEC_REF(); + + static_assert(ptr_traits_passes_virtual_destructor_check::requires_virtual_destructor_check>::value, "Destructor is not virtual"); } unique_ptr(const unique_ptr&) noexcept = delete; template unique_ptr(unique_ptr&& other) noexcept @@ -396,6 +412,8 @@ public: } ~unique_ref() noexcept { + static_assert(ptr_traits_passes_virtual_destructor_check::requires_virtual_destructor_check>::value, "Destructor is not virtual"); + m_del.destroy(m_ptr); CB_UNIQUE_DEC_REF(); } @@ -556,6 +574,12 @@ public: { CB_LENT_COPY_CTOR(); } + + template lent_ptr(unique_ref&& other) = delete; + template lent_ptr(unique_ptr&& other) = delete; + template lent_ptr& operator = (unique_ref&& other) = delete; + template lent_ptr& operator = (unique_ptr&& other) = delete; + template lent_ptr(lent_ptr&& other) noexcept : m_ptr(other.m_ptr) { @@ -722,6 +746,10 @@ public: CHECK_NULL; CB_LENT_COPY_CTOR(); } + + template lent_ref(unique_ref&& other) = delete; + template lent_ref& operator = (unique_ref&& other) = delete; + lent_ref(lent_ref&& other) noexcept : m_ptr(other.m_ptr) {