Skip to content

[BUG]: c4800 warning when compiling with MSVC and python 3.10 #3668

@SergeyKrivohatskiy

Description

@SergeyKrivohatskiy

Required prerequisites

Problem description

Python 3.9 to Python 3.10 changed this code:

#define PyObject_TypeCheck(ob, tp) \
    (Py_IS_TYPE(ob, tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))

to this code:

static inline int _PyObject_TypeCheck(PyObject *ob, PyTypeObject *type) {
    return Py_IS_TYPE(ob, type) || PyType_IsSubtype(Py_TYPE(ob), type);
}
#define PyObject_TypeCheck(ob, type) _PyObject_TypeCheck(_PyObject_CAST(ob), type)

That change gives two c4800 warnings here:

    bool PyArray_Check_(PyObject *obj) const {
        return (bool) PyObject_TypeCheck(obj, PyArray_Type_);
    }
    bool PyArrayDescr_Check_(PyObject *obj) const {
        return (bool) PyObject_TypeCheck(obj, PyArrayDescr_Type_);
    }

pybind11/numpy.h(173): warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
pybind11/numpy.h(176): warning C4800: 'int': forcing value to bool 'true' or 'false' (performance warning)

Consider changing to something like this given you've done similar fixes:

    bool PyArray_Check_(PyObject *obj) const {
        return PyObject_TypeCheck(obj, PyArray_Type_) != 0;
    }
    bool PyArrayDescr_Check_(PyObject *obj) const {
        return PyObject_TypeCheck(obj, PyArrayDescr_Type_) != 0;
    }

P.S. I'm sorry this is not a PR. But I don't wanna set up everything for such a small change

Reproducible example code

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions