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.
changed the title [-]C++-friendly _Py_CAST macro breaks unicodeobject.h on C++[/-][+]C++-warningless _Py_CAST macro breaks unicodeobject.h on C++[/+]on May 14, 2022
changed the title [-]C++-warningless _Py_CAST macro breaks unicodeobject.h on C++[/-][+]PyUnicode_READ() fails to build on C++: _Py_CAST() used with a constant type (const void*)[/+]on May 17, 2022
Activity
tacaswell commented on May 14, 2022
This issue is scattered across a couple of places (which may be my fault) here is an index of the relevant links:
vstinner commented on May 17, 2022
The C++ project scipy fails to build with:
/home/tcaswell/.pybuild/bleeding/include/python3.11/cpython/unicodeobject.h:409:57: error: duplicate ‘const’ 409 | PyUnicode_READ(_Py_STATIC_CAST(int, kind), _Py_CAST(const void*, data), \ | ^~~~~Oh right, that's my fault, _Py_CAST() cannot be used with a const type. _Py_CAST() comment:
vstinner commented on May 17, 2022
Would you be able to test if #92872 fix scipy?
tacaswell commented on May 17, 2022
I can confirm that scipy (and a large fraction of the pydata stack) build with #92872 .
vstinner commented on May 17, 2022
Fixed by #92872 : thanks for the bug report!
Fix C++ _Py_CAST with constant types