summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-06-14 09:43:08 (GMT)
committerGitHub <noreply@github.com>2022-06-14 09:43:08 (GMT)
commit4caf5c2753f1aa28d6f4bc1aa377975fd2a62331 (patch)
treef04937769184fe84dfeda70dcfc58202c39cf693 /Include
parent3597c129413a86f805beca78b7c72a20b5bf801c (diff)
downloadcpython-4caf5c2753f1aa28d6f4bc1aa377975fd2a62331.zip
cpython-4caf5c2753f1aa28d6f4bc1aa377975fd2a62331.tar.gz
cpython-4caf5c2753f1aa28d6f4bc1aa377975fd2a62331.tar.bz2
gh-91321: Fix compatibility with C++ older than C++11 (#93784)
Fix the compatibility of the Python C API with C++ older than C++11. _Py_NULL is only defined as nullptr on C++11 and newer.
Diffstat (limited to 'Include')
-rw-r--r--Include/pyport.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/Include/pyport.h b/Include/pyport.h
index faaeb83..313bc8d 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -36,10 +36,12 @@ extern "C++" {
inline type _Py_CAST_impl(int ptr) {
return reinterpret_cast<type>(ptr);
}
+#if __cplusplus >= 201103
template <typename type>
inline type _Py_CAST_impl(std::nullptr_t) {
return static_cast<type>(nullptr);
}
+#endif
template <typename type, typename expr_type>
inline type _Py_CAST_impl(expr_type *expr) {
@@ -70,8 +72,9 @@ extern "C++" {
#endif
// Static inline functions should use _Py_NULL rather than using directly NULL
-// to prevent C++ compiler warnings. In C++, _Py_NULL uses nullptr.
-#ifdef __cplusplus
+// to prevent C++ compiler warnings. On C++11 and newer, _Py_NULL is defined as
+// nullptr.
+#if defined(__cplusplus) && __cplusplus >= 201103
# define _Py_NULL nullptr
#else
# define _Py_NULL NULL