Skip to content

Commit a0f862d

Browse files
authored
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).
1 parent 7f76d79 commit a0f862d

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

include/pybind11/buffer_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct buffer_info {
8383
view->strides
8484
? std::vector<ssize_t>(view->strides, view->strides + view->ndim)
8585
: detail::c_strides({view->shape, view->shape + view->ndim}, view->itemsize),
86-
view->readonly) {
86+
(view->readonly != 0)) {
8787
this->m_view = view;
8888
this->ownview = ownview;
8989
}

include/pybind11/cast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ template <> class type_caster<bool> {
322322
}
323323
#endif
324324
if (res == 0 || res == 1) {
325-
value = (bool) res;
325+
value = (res != 0);
326326
return true;
327327
}
328328
PyErr_Clear();

include/pybind11/detail/type_caster_base.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ struct value_and_holder {
231231
return reinterpret_cast<V *&>(vh[0]);
232232
}
233233
// True if this `value_and_holder` has a non-null value pointer
234-
explicit operator bool() const { return value_ptr(); }
234+
explicit operator bool() const { return value_ptr() != nullptr; }
235235

236236
template <typename H> H &holder() const {
237237
return reinterpret_cast<H &>(vh[1]);
@@ -252,7 +252,7 @@ struct value_and_holder {
252252
bool instance_registered() const {
253253
return inst->simple_layout
254254
? inst->simple_instance_registered
255-
: inst->nonsimple.status[index] & instance::status_instance_registered;
255+
: ((inst->nonsimple.status[index] & instance::status_instance_registered) != 0);
256256
}
257257
void set_instance_registered(bool v = true) const {
258258
if (inst->simple_layout)

include/pybind11/pybind11.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# pragma warning(push)
1919
# pragma warning(disable: 4100) // warning C4100: Unreferenced formal parameter
2020
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
21-
# pragma warning(disable: 4800) // warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
2221
# pragma warning(disable: 4505) // warning C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only)
2322
#elif defined(__GNUG__) && !defined(__clang__)
2423
# pragma GCC diagnostic push

include/pybind11/pytypes.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ class PYBIND11_EXPORT error_already_set : public std::runtime_error {
367367
/// Check if the currently trapped error type matches the given Python exception class (or a
368368
/// subclass thereof). May also be passed a tuple to search for any exception class matches in
369369
/// the given tuple.
370-
bool matches(handle exc) const { return PyErr_GivenExceptionMatches(m_type.ptr(), exc.ptr()); }
370+
bool matches(handle exc) const {
371+
return (PyErr_GivenExceptionMatches(m_type.ptr(), exc.ptr()) != 0);
372+
}
371373

372374
const object& type() const { return m_type; }
373375
const object& value() const { return m_value; }
@@ -853,7 +855,7 @@ PYBIND11_NAMESPACE_END(detail)
853855
Name(handle h, borrowed_t) : Parent(h, borrowed_t{}) { } \
854856
Name(handle h, stolen_t) : Parent(h, stolen_t{}) { } \
855857
PYBIND11_DEPRECATED("Use py::isinstance<py::python_type>(obj) instead") \
856-
bool check() const { return m_ptr != nullptr && (bool) CheckFun(m_ptr); } \
858+
bool check() const { return m_ptr != nullptr && (CheckFun(m_ptr) != 0); } \
857859
static bool check_(handle h) { return h.ptr() != nullptr && CheckFun(h.ptr()); } \
858860
template <typename Policy_> \
859861
Name(const ::pybind11::detail::accessor<Policy_> &a) : Name(object(a)) { }

0 commit comments

Comments
 (0)