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).
This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-07-26 13:26:36 -07:00 committed by Henry Schreiner
parent c973660d6c
commit e93d94594b
No known key found for this signature in database
GPG Key ID: B9D0E45146A241E8
5 changed files with 8 additions and 7 deletions

View File

@ -83,7 +83,7 @@ struct buffer_info {
view->strides
? std::vector<ssize_t>(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;
}

View File

@ -322,7 +322,7 @@ public:
}
#endif
if (res == 0 || res == 1) {
value = (bool) res;
value = (res != 0);
return true;
}
PyErr_Clear();

View File

@ -231,7 +231,7 @@ struct value_and_holder {
return reinterpret_cast<V *&>(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 <typename H> H &holder() const {
return reinterpret_cast<H &>(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)

View File

@ -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

View File

@ -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<py::python_type>(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 <typename Policy_> \
Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) { }