diff --git a/Include/pyport.h b/Include/pyport.h index 61e2317976eed1..a489851e57a87d 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -282,6 +282,8 @@ extern "C" { #elif defined(_MSC_VER) #define Py_DEPRECATED(VERSION) __declspec(deprecated( \ "deprecated in " #VERSION)) +#elif __STDC_VERSION__ >= 202311L || __cplusplus >= 201402L +#define Py_DEPRECATED(VERSION) [[deprecated("Deprecated in "#VERSION)]] #else #define Py_DEPRECATED(VERSION_UNUSED) #endif @@ -642,6 +644,30 @@ extern "C" { # endif #endif +#ifndef PY_CXX_CONSTEXPR +# if defined(__cplusplus) || __STDC_VERSION__ >= 202311L +# define PY_CXX_CONSTEXPR constexpr +# else +# define PY_CXX_CONSTEXPR +# endif +#endif + +#ifndef PY_CXX_CONSTEVAL +# ifdef __cpp_consteval +# define PY_CXX_CONSTEVAL consteval +# else +# define PY_CXX_CONSTEVAL +# endif +#endif + +#ifndef PY_CXX_CONSTINIT +# ifdef __cpp_constinit +# define PY_CXX_CONSTINIT constinit +# else +# define PY_CXX_CONSTINIT +# endif +#endif + #if defined(__sgi) && !defined(_SGI_MP_SOURCE) # define _SGI_MP_SOURCE #endif diff --git a/Misc/NEWS.d/next/C_API/2026-01-02-13-46-01.gh-issue-143353.Hy-0xm.rst b/Misc/NEWS.d/next/C_API/2026-01-02-13-46-01.gh-issue-143353.Hy-0xm.rst new file mode 100644 index 00000000000000..dc91e9f7f99e6b --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2026-01-02-13-46-01.gh-issue-143353.Hy-0xm.rst @@ -0,0 +1 @@ +Add macros for annotating functions with constexpr, consteval, and constinit