Skip to content

gh-160704: Restore C11-C17 static_assert fallback - #160705

Merged
encukou merged 1 commit into
python:mainfrom
ZhongRuoyu:restore-static_assert-fallback
Oct 28, 2026
Merged

encukou merged 1 commit into
python:mainfrom
ZhongRuoyu:restore-static_assert-fallback

Conversation

@ZhongRuoyu

@ZhongRuoyu ZhongRuoyu commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

_Py_STDC_VERSION needs to be defined before its value can be checked. In 8335bcb (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.

Please backport to 3.15.

CC: @encukou

`_Py_STDC_VERSION` needs to be defined before its value can be checked.
In 8335bcb (pythongh-160208: Add a private wrapper around __STDC_VERSION__
(pythonGH-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 <zhongruoyu@outlook.com>
@StanFromIreland StanFromIreland added the needs backport to 3.15 bugs and security fixes label Oct 26, 2026
@encukou
encukou merged commit a7ac7a8 into python:main Oct 28, 2026
64 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @ZhongRuoyu for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 28, 2026

Copy link
Copy Markdown

GH-160825 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 28, 2026
encukou pushed a commit that referenced this pull request Oct 28, 2026
GH-160825)

gh-160704: Restore C11-C17 `static_assert` fallback (GH-160705)

`_Py_STDC_VERSION` needs to be defined before its value can be checked.
In 8335bcb (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`.
(cherry picked from commit a7ac7a8)

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
Co-authored-by: Ruoyu Zhong <zhongruoyu@outlook.com>
@ZhongRuoyu
ZhongRuoyu deleted the restore-static_assert-fallback branch October 28, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants