From e06aab3969fa2560f1896a0072a861ba14921499 Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Mon, 26 Oct 2026 21:24:14 +0800 Subject: [PATCH] gh-160704: Restore C11-C17 `static_assert` fallback `_Py_STDC_VERSION` needs to be defined before its value can be checked. In 8335bcbf26b (gh-160208: Add a private wrapper around __STDC_VERSION__ (GH-160376), 2026-10-23), the condition `defined(_Py_STDC_VERSION)` is incorrectly negated, which prevents the fallback definition of `static_assert` in C11-C17 builds and causes a build error when building with an old C library that does not define `static_assert`. Below is an example when building CPython 3.15.2 with glibc 2.13: gcc -pthread -c -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -std=c11 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -fvisibility=hidden -I/usr/local/src/python/Include/internal -I/usr/local/src/python/Include/internal/mimalloc -IObjects -IInclude -IPython -I. -I/usr/local/src/python/Include -DPy_BUILD_CORE -o Objects/longobject.o /usr/local/src/python/Objects/longobject.c In file included from /usr/local/src/python/Include/Python.h:70, from /usr/local/src/python/Objects/longobject.c:5: /usr/local/src/python/Include/internal/pycore_bitutils.h: In function '_Py_popcount32': /usr/local/src/python/Include/pymacro.h:175:13: error: implicit declaration of function 'static_assert' [-Wimplicit-function-declaration] 175 | static_assert((cond), #cond); \ | ^~~~~~~~~~~~~ /usr/local/src/python/Include/internal/pycore_bitutils.h:100:5: note: in expansion of macro 'Py_BUILD_ASSERT' 100 | Py_BUILD_ASSERT(sizeof(x) <= sizeof(unsigned int)); | ^~~~~~~~~~~~~~~ make: *** [Makefile:3407: Objects/longobject.o] Error 1 Restore compilation in such environments by fixing the negation. Signed-off-by: Ruoyu Zhong --- Include/pymacro.h | 2 +- .../next/Build/2026-10-26-21-00-00.gh-issue-160704.ZRYLKF.rst | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Build/2026-10-26-21-00-00.gh-issue-160704.ZRYLKF.rst diff --git a/Include/pymacro.h b/Include/pymacro.h index 73521be00fcd1ad..f08ed1a1ecf0f9f 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -25,7 +25,7 @@ // behaviour. So only define if building as C, not C++ (if __cplusplus is // not defined), and only for C11-17. #if !defined(static_assert) && (defined(__GNUC__) || defined(__clang__)) \ - && !defined(_Py_STDC_VERSION) \ + && defined(_Py_STDC_VERSION) \ && _Py_STDC_VERSION >= 201112L && _Py_STDC_VERSION <= 201710L # define static_assert _Static_assert #endif diff --git a/Misc/NEWS.d/next/Build/2026-10-26-21-00-00.gh-issue-160704.ZRYLKF.rst b/Misc/NEWS.d/next/Build/2026-10-26-21-00-00.gh-issue-160704.ZRYLKF.rst new file mode 100644 index 000000000000000..330415c155cd89a --- /dev/null +++ b/Misc/NEWS.d/next/Build/2026-10-26-21-00-00.gh-issue-160704.ZRYLKF.rst @@ -0,0 +1,2 @@ +Fix C11-C17 builds with old C library headers that do not define +``static_assert``, including glibc versions older than 2.16.