Skip to content

gh-154643: Only use _Py_STDC_VERSION when defined - #154650

Merged
encukou merged 4 commits into
python:mainfrom
hroncok:__STDC_VERSION__
Nov 11, 2026
Merged

encukou merged 4 commits into
python:mainfrom
hroncok:__STDC_VERSION__

Conversation

@hroncok

@hroncok hroncok commented Jul 24, 2026 •

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: ‘__STDC_VERSION__’ is not defined, evaluates to ‘0’ [-Werror=undef]
  494 | #  elif __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 but was left untouched as it is code from a bundled project and is likely not exposed publicly.

Assisted-By: Claude Opus 4.6

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 90 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Oct 29, 2026
@hroncok

hroncok commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

I am unsure what more activity I shall provide. I can rebase it perhaps.

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
@hroncok hroncok changed the title gh-154643: Only use __STDC_VERSION__ when defined gh-154643: Only use _Py_STDC_VERSION when defined Oct 29, 2026
@hroncok

hroncok commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Rebased.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Nov 6, 2026
@hroncok

hroncok commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@encukou Coudl you please have a look at this? The #160376 change made this surface on C as well.

@encukou encukou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks for the ping.

Comment thread Lib/test/test_cext/__init__.py Resolved
@encukou

encukou commented Nov 9, 2026

Copy link
Copy Markdown
Member

Instead. These tests already take a long time, I'd prefer avoiding an extra run per flag.

@hroncok

hroncok commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Done.

@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 10, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 01036ec 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F154650%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 10, 2026
@encukou
encukou merged commit de9a4fb into python:main Nov 11, 2026
136 of 140 checks passed
@hroncok
hroncok deleted the __STDC_VERSION__ branch November 11, 2026 12:20
orsenthil pushed a commit to orsenthil/cpython that referenced this pull request Nov 12, 2026
)

* 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
@encukou encukou added the needs backport to 3.15 bugs and security fixes label Nov 12, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @hroncok 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 Nov 12, 2026

Copy link
Copy Markdown

GH-161874 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 Nov 12, 2026
encukou pushed a commit that referenced this pull request Nov 12, 2026
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