From e93d94594b063682a70ead0b7feb8c1329ae0717 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Mon, 26 Jul 2021 13:26:36 -0700 Subject: [PATCH] Removing MSVC C4800 from pragma block at the top of pybind11.h (#3141) * Adding PYBIND11_COMPAT_BOOL_CAST to appease MSVC 2015 warning C4800. * Replacing PYBIND11_COMPAT_BOOL_CAST with simpler != 0 * Extra parentheses (almost all compilers failed without these). --- include/pybind11/buffer_info.h | 2 +- include/pybind11/cast.h | 2 +- include/pybind11/detail/type_caster_base.h | 4 ++-- include/pybind11/pybind11.h | 1 - include/pybind11/pytypes.h | 6 ++++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/pybind11/buffer_info.h b/include/pybind11/buffer_info.h index 47dc39d4e..eba68d1aa 100644 --- a/include/pybind11/buffer_info.h +++ b/include/pybind11/buffer_info.h @@ -83,7 +83,7 @@ struct buffer_info { view->strides ? std::vector(view->strides, view->strides + view->ndim) : detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize), - view->readonly) { + (view->readonly != 0)) { this->m_view = view; this->ownview = ownview; } diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index a748c77c0..1da432358 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -322,7 +322,7 @@ public: } #endif if (res == 0 || res == 1) { - value = (bool) res; + value = (res != 0); return true; } PyErr_Clear(); diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 451690dc7..39d0740ff 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -231,7 +231,7 @@ struct value_and_holder { return reinterpret_cast(vh[0]); } // True if this `value_and_holder` has a non-null value pointer - explicit operator bool() const { return value_ptr(); } + explicit operator bool() const { return value_ptr() != nullptr; } template H &holder() const { return reinterpret_cast(vh[1]); @@ -252,7 +252,7 @@ struct value_and_holder { bool instance_registered() const { return inst->simple_layout ? inst->simple_instance_registered - : inst->nonsimple.status[index] & instance::status_instance_registered; + : ((inst->nonsimple.status[index] & instance::status_instance_registered) != 0); } void set_instance_registered(bool v = true) const { if (inst->simple_layout) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index b5091ff25..6a2bd0f24 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -18,7 +18,6 @@ # pragma warning(push) # pragma warning(disable: 4100) // warning C4100: Unreferenced formal parameter # pragma warning(disable: 4127) // warning C4127: Conditional expression is constant -# pragma warning(disable: 4800) // warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning) # pragma warning(disable: 4505) // warning C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only) #elif defined(__GNUG__) && !defined(__clang__) # pragma GCC diagnostic push diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 332998277..cea4e7eb0 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -367,7 +367,9 @@ public: /// Check if the currently trapped error type matches the given Python exception class (or a /// subclass thereof). May also be passed a tuple to search for any exception class matches in /// the given tuple. - bool matches(handle exc) const { return PyErr_GivenExceptionMatches(m_type.ptr(), exc.ptr()); } + bool matches(handle exc) const { + return (PyErr_GivenExceptionMatches(m_type.ptr(), exc.ptr()) != 0); + } const object& type() const { return m_type; } const object& value() const { return m_value; } @@ -853,7 +855,7 @@ PYBIND11_NAMESPACE_END(detail) Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) { } \ Name(handle h, stolen_t) : Parent(h, stolen_t{}) { } \ PYBIND11_DEPRECATED("Use py::isinstance(obj) instead") \ - bool check() const { return m_ptr != nullptr && (bool) CheckFun(m_ptr); } \ + bool check() const { return m_ptr != nullptr && (CheckFun(m_ptr) != 0); } \ static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); } \ template \ Name(const ::pybind11::detail::accessor &a) : Name(object(a)) { }