mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[3.11] GH-92898: Make _Py_Cast C++ version compatible with cast operator (gh-92951) (gh-93049)
This commit is contained in:
parent
d9a48d2b41
commit
dd923c5725
2 changed files with 35 additions and 2 deletions
|
|
@ -26,8 +26,32 @@
|
|||
// _Py_CAST(const PyObject*, expr) fails with a compiler error.
|
||||
#ifdef __cplusplus
|
||||
# define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)
|
||||
# define _Py_CAST(type, expr) \
|
||||
const_cast<type>(reinterpret_cast<const type>(expr))
|
||||
|
||||
extern "C++" {
|
||||
namespace {
|
||||
template <typename type, typename expr_type>
|
||||
inline type _Py_reinterpret_cast_impl(expr_type *expr) {
|
||||
return reinterpret_cast<type>(expr);
|
||||
}
|
||||
|
||||
template <typename type, typename expr_type>
|
||||
inline type _Py_reinterpret_cast_impl(expr_type const *expr) {
|
||||
return reinterpret_cast<type>(const_cast<expr_type *>(expr));
|
||||
}
|
||||
|
||||
template <typename type, typename expr_type>
|
||||
inline type _Py_reinterpret_cast_impl(expr_type &expr) {
|
||||
return static_cast<type>(expr);
|
||||
}
|
||||
|
||||
template <typename type, typename expr_type>
|
||||
inline type _Py_reinterpret_cast_impl(expr_type const &expr) {
|
||||
return static_cast<type>(const_cast<expr_type &>(expr));
|
||||
}
|
||||
} // namespace
|
||||
}
|
||||
# define _Py_CAST(type, expr) _Py_reinterpret_cast_impl<type>(expr)
|
||||
|
||||
#else
|
||||
# define _Py_STATIC_CAST(type, expr) ((type)(expr))
|
||||
# define _Py_CAST(type, expr) ((type)(expr))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue