Description
Bug report
The new _Py_CAST
macro (https://github.com/python/cpython/pull/91959/files, and other commits) designed to reduce C++ warnings adds a fairly significant restriction that wasn't there before
Lines 25 to 26 in 9f68dab
The PyUnicode_READ macro casts to a const pointer
cpython/Include/cpython/unicodeobject.h
Lines 341 to 343 in 9f68dab
This is currently reported to be breaking Cython (cython/cython#4790).
I'd propose a fix which removes the const requirement:
template <typename T>
struct _Py_add_const {
typedef const T type;
};
# define _Py_CAST(tp, expr) \
const_cast<tp>(reinterpret_cast<_Py_add_const<tp>::type>(expr))
on C++11 you could use the standard library std::add_cast
instead, at the cost of an extra include. However it isn't available on c++03.
I realise this adds an extra struct _Py_add_const
to the namespace. I'm not sure if that's desired, or how it should be named. If that's acceptable I'm happy to submit a PR for this.
Your environment
Current 3.11 branch