Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In C++, Python 3.11 C API introduces new compiler warnings/errors #92135

Closed
vstinner opened this issue May 2, 2022 · 2 comments
Closed

In C++, Python 3.11 C API introduces new compiler warnings/errors #92135

vstinner opened this issue May 2, 2022 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@vstinner
Copy link
Member

vstinner commented May 2, 2022

To fix C++ compiler warnings about "old-style casts", I recently modified the Python C API to use C++ reinterpret_cast<> and static_cast<>: #91959

Previously, "old-style cast" like (PyObject*)expr didn't emit a compiler warning if expr was const. Now with the new cast, C++ compilers emit warnings: see #91959 (comment)

const_cast<> can be used to fix this issue.

Note: PEP 670 was accepted with the condition: converting macros to functions must not introduce new compiler warnings (so no new compile errors neither). But most functions modified in Python 3.11 (to use C++ casts) were already static inline functions in Python 3.10.

@vstinner vstinner added the type-bug An unexpected behavior, bug, or error label May 2, 2022
@vstinner
Copy link
Member Author

vstinner commented May 2, 2022

Documentation:

vstinner added a commit that referenced this issue May 2, 2022
Fix C++ compiler warnings on cast macros, like _PyObject_CAST(), when
casting a constant expression to a non constant type: use
const_cast<> in C++.

* In C++, Py_SAFE_DOWNCAST() now uses static_cast<> rather than
  reinterpret_cast<>.
* Add tests to the _testcppext C++ extension.
* test_cppext no longer captures stdout in verbose mode.
@vstinner
Copy link
Member Author

vstinner commented May 2, 2022

Fixed by #92138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant