Skip to content

[3.15] gh-154643: Only use _Py_STDC_VERSION when defined (GH-154650) - #161874

Merged
encukou merged 1 commit into
python:3.15from
miss-islington:backport-de9a4fb-3.15
Nov 12, 2026
Merged

encukou merged 1 commit into
python:3.15from
miss-islington:backport-de9a4fb-3.15

Conversation

@miss-islington

Copy link
Copy Markdown
Contributor

This fixes:

$ g++ -I/usr/include/python3.15 -c -Werror=undef test.cpp
In file included from /usr/include/python3.15/Python.h:68,
                 from test.cpp:1:
/usr/include/python3.15/pyport.h:494:9: error: ‘_Py_STDC_VERSION’ is not defined, evaluates to ‘0’ [-Werror=undef]
  494 | #  elif _Py_STDC_VERSION >= 201112L && !defined(__STDC_NO_THREADS__)
      |         ^~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors

For any test.cpp that has #include <Python.h>.

For locating the place for the added test, I used LLM.

The main issue I could reproduce was in Include/pyport.h.
Include/cpython/pyatomic.h was updated for completeness.

Include/internal/mimalloc/mimalloc/atomic.h also has this
for STDC_VERSION
but was left untouched as it is code from a bundled project
and is likely not exposed publicly.

Assisted-By: Claude Opus 4.6

  • Also add test for C

  • Add -Werror=undef to PUBLIC_CFLAGS & PEDANTIC_CXXFLAGS in setup.py

  • Drop tests, we use PUBLIC_CFLAGS & PEDANTIC_CXXFLAGS instead
    (cherry picked from commit de9a4fb)

Co-authored-by: Miro Hrončok miro@hroncok.cz

)

* pythongh-154643: Only use _Py_STDC_VERSION when defined

This fixes:

    $ g++ -I/usr/include/python3.15 -c -Werror=undef test.cpp
    In file included from /usr/include/python3.15/Python.h:68,
                     from test.cpp:1:
    /usr/include/python3.15/pyport.h:494:9: error: ‘_Py_STDC_VERSION’ is not defined, evaluates to ‘0’ [-Werror=undef]
      494 | #  elif _Py_STDC_VERSION >= 201112L && !defined(__STDC_NO_THREADS__)
          |         ^~~~~~~~~~~~~~~~
    cc1plus: some warnings being treated as errors

For any test.cpp that has #include <Python.h>.

For locating the place for the added test, I used LLM.

The main issue I could reproduce was in Include/pyport.h.
Include/cpython/pyatomic.h was updated for completeness.

Include/internal/mimalloc/mimalloc/atomic.h also has this
for __STDC_VERSION__
but was left untouched as it is code from a bundled project
and is likely not exposed publicly.

Assisted-By: Claude Opus 4.6

* Also add test for C

* Add -Werror=undef to PUBLIC_CFLAGS & PEDANTIC_CXXFLAGS in setup.py

* Drop tests, we use PUBLIC_CFLAGS & PEDANTIC_CXXFLAGS instead
(cherry picked from commit de9a4fb)

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
@encukou
encukou merged commit beff3c0 into python:3.15 Nov 12, 2026
55 checks passed
@miss-islington
miss-islington deleted the backport-de9a4fb-3.15 branch November 12, 2026 15:39
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