diff --git a/Include/objimpl.h b/Include/objimpl.h --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -166,6 +166,28 @@ #define PyObject_INIT_VAR(op, typeobj, size) \ ( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) ) +#ifdef __clang__ +/* Clang warns about unused expressions like the expansions of PyObject_INIT and + * PyObject_INIT_VAR. Replace them by static inline definitions. + */ +static __inline__ PyObject* _PyObject_INIT(PyObject* op, PyTypeObject* typeobj) +{ + return PyObject_INIT(op, typeobj); +} + +static __inline__ PyVarObject* _PyObject_INIT_VAR(PyVarObject* op, PyTypeObject* typeobj, Py_ssize_t n) +{ + return PyObject_INIT_VAR(op, typeobj, n); +} + + +#undef PyObject_INIT +#undef PyObject_INIT_VAR + +#define PyObject_INIT(op, typeobj) _PyObject_INIT((PyObject*)op, typeobj) +#define PyObject_INIT_VAR(op, typeobj, n) _PyObject_INIT_VAR((PyVarObject*)op, typeobj, n) +#endif + #define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize ) /* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for a