| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Fix C++ compiler warnings: "zero as null pointer constant" (clang -Wzero-as-null-pointer-constant). * Add the _Py_NULL macro used by static inline functions to use nullptr in C++. * Replace NULL with nullptr in _testcppext.cpp.
|
I already had this issue and fixed it in pythoncapi-compat. I prepared a PR for pythoncapi-compat to reuse Python 3.11 _Py_NULL macro (this PR): python/pythoncapi-compat#36 |
Sorry, something went wrong.
|
Currently, with gcc -Wzero-as-null-pointer-constant, there is no C++ compiler warning when including <Python.h>. But using clang -Wzero-as-null-pointer-constant, I get many warnings (errors). A few examples: $ CC=clang ./python -m test -v test_cppext
(...)
In file included from /home/vstinner/python/main/Lib/test/_testcppext.cpp:7:
In file included from /home/vstinner/python/main/Include/Python.h:44:
/home/vstinner/python/main/Include/object.h:590:15: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
if (op != NULL) {
^~~~
nullptr
/usr/lib64/clang/13.0.0/include/stddef.h:84:18: note: expanded from macro 'NULL'
# define NULL __null
^
In file included from /home/vstinner/python/main/Lib/test/_testcppext.cpp:7:
In file included from /home/vstinner/python/main/Include/Python.h:44:
/home/vstinner/python/main/Include/object.h:600:15: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
if (op != NULL) {
^~~~
nullptr
/usr/lib64/clang/13.0.0/include/stddef.h:84:18: note: expanded from macro 'NULL'
# define NULL __null
^
In file included from /home/vstinner/python/main/Lib/test/_testcppext.cpp:7:
In file included from /home/vstinner/python/main/Include/Python.h:51:
In file included from /home/vstinner/python/main/Include/unicodeobject.h:1042:
/home/vstinner/python/main/Include/cpython/unicodeobject.h:645:42: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
if (_PyASCIIObject_CAST(op)->wstr == NULL) {
^~~~
nullptr
/usr/lib64/clang/13.0.0/include/stddef.h:84:18: note: expanded from macro 'NULL'
# define NULL __null
^
(...)
Tests result: FAILURE
|
Sorry, something went wrong.
|
I also got these errors on the CI of the datatabl project: see h2oai/datatable#3231 |
Sorry, something went wrong.
|
This breaks C-extensions builds with , e.g., -std=c++03, because nullptr is only defined since C++11 |
Sorry, something went wrong.
|
In Python 3.11, I added test_cppext which checks that the Python C API is compatible with C++11. Do you care about older C++ versions? What is your OS (name and version) and C++ compiler (name and version)? |
Sorry, something went wrong.
|
Actually we're explicitly requiring -std=c++03 in a couple Cython files. |
Sorry, something went wrong.
|
I wrote #93784 to fix compatibility with C++ older than C++11. |
Sorry, something went wrong.
It's not intentional. My initial concern was to prevent C++ compiler warnings. |
Sorry, something went wrong.
|
Awesome, thank you very much ! |
Sorry, something went wrong.
|
Python 3.11 is now fixed: |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fix C++ compiler warnings: "zero as null pointer constant"
(clang -Wzero-as-null-pointer-constant).
nullptr in C++.