From 223283295f121e3a002e87ffa1a31699690840f6 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sat, 19 Jun 2021 23:52:17 -0700 Subject: [PATCH] Two minor platform-specific fixes. Using static_cast instead of reinterpret_cast. --- include/pybind11/detail/smart_holder_poc.h | 8 ++++---- tests/test_class_sh_shared_from_this.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/pybind11/detail/smart_holder_poc.h b/include/pybind11/detail/smart_holder_poc.h index 0629ab696..11386044d 100644 --- a/include/pybind11/detail/smart_holder_poc.h +++ b/include/pybind11/detail/smart_holder_poc.h @@ -92,12 +92,12 @@ to_cout("LOOOK guarded_delete ctor " + std::to_string(__LINE__) + " " + __FILE__ template inline void shd_ptr_reset(std::shared_ptr& shd_ptr, void *raw_ptr, guarded_delete &&gdel) { - shd_ptr.reset(reinterpret_cast(raw_ptr), gdel); + shd_ptr.reset(static_cast(raw_ptr), gdel); } template ::value, int>::type = 0> inline void builtin_delete_if_destructible(void *raw_ptr) { - delete reinterpret_cast(raw_ptr); + delete static_cast(raw_ptr); } template ::value, int>::type = 0> @@ -115,7 +115,7 @@ guarded_delete make_guarded_builtin_delete(bool armed_flag) { template inline void custom_delete(void *raw_ptr) { - D()(reinterpret_cast(raw_ptr)); + D()(static_cast(raw_ptr)); } template @@ -245,7 +245,7 @@ to_cout("LOOOK smart_holder from_raw_ptr_unowned " + std::to_string(__LINE__) + template T *as_raw_ptr_unowned() const { -to_cout("LOOOK smart_holder as_raw_ptr_unowned PTR" + std::to_string((unsigned long) vptr.get()) + " " + std::to_string(__LINE__) + " " + __FILE__); +to_cout("LOOOK smart_holder as_raw_ptr_unowned " + std::to_string(__LINE__) + " " + __FILE__); return static_cast(vptr.get()); } diff --git a/tests/test_class_sh_shared_from_this.cpp b/tests/test_class_sh_shared_from_this.cpp index a021d4e42..442b80c48 100644 --- a/tests/test_class_sh_shared_from_this.cpp +++ b/tests/test_class_sh_shared_from_this.cpp @@ -112,7 +112,7 @@ struct RescuingDeleter { explicit RescuingDeleter(PyWrapper *pyw) : pyw{pyw} {} void operator()(ToBeWrapped *raw_ptr) { if (pyw->self.get() != nullptr) { -#if !defined(_MSC_VER) || _MSC_VER >= 1912 +#if defined(__cpp_lib_enable_shared_from_this) && (!defined(_MSC_VER) || _MSC_VER >= 1912) assert(raw_ptr->weak_from_this().expired()); // CRITICAL #endif pyw->wobj = std::shared_ptr(raw_ptr, *this);