Skip to content

gh-160208: Fix _Py_ANONYMOUS on C++ - #160332

Closed
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:anonymous
Closed

vstinner wants to merge 1 commit into
python:mainfrom
vstinner:anonymous

Conversation

@vstinner

@vstinner vstinner commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Use __extension__ on g++/clang++ to fix this g++ warning on Include/object.h:

error: ISO C++ prohibits anonymous structs [-Wpedantic]

Use __extension__ on g++/clang++ to fix this g++ warning on
Include/object.h:

    error: ISO C++ prohibits anonymous structs [-Wpedantic]
@vstinner

Copy link
Copy Markdown
Member Author

The change should be backported manually to 3.14 which doesn't have _Py_ANONYMOUS macro. I suppose that this macro should be backported to 3.14 as well.

@vstinner

Copy link
Copy Markdown
Member Author

Without this change, two C++ tests of test_cext fails on OpenIndiana with g++ 14.3.0.

With this change, test_cext pass on the same machine.

@vstinner

Copy link
Copy Markdown
Member Author

@mtelka: Would you mind to test this change?

cc @encukou

@vstinner

Copy link
Copy Markdown
Member Author

This change is needed on OpenIndiana where <stdint.h> defines __STDC_VERSION__ macro even in C++.

@mtelka

mtelka commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

This change is needed on OpenIndiana where <stdint.h> defines __STDC_VERSION__ macro even in C++.

@vstinner Isn't this a bug in OpenIndiana (illumos) then? If so, it should be fixed there...

@mtelka

mtelka commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

This is related illumos bug report: https://www.illumos.org/issues/14920

@mtelka

mtelka commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

... and because of this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57025#c13 I think this PR makes sense.

I'm just testing this change with Python 3.15.1 on OpenIndiana and I'll report back how it went.

@mtelka

mtelka commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

I can confirm that this PR fixes the test_cext failure on OpenIndiana.
Thank you!

@encukou

encukou commented Oct 22, 2026

Copy link
Copy Markdown
Member

I think we want a more robust approach here, given the comment https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57025#c4:

the C++ standard allows __STDC_VERSION to be defined by a C++ compiler.

Let me think about this a bit.

@vstinner

Copy link
Copy Markdown
Member Author

Before my change, !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) is false with g++ on OpenIndiana and so __extension__ is not used.

With my change, (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(__cplusplus)) is true with g++ on OpenIndiana (since C++ compilers define __cplusplus macro), and so __extension__ is used as expected.

__extension__ is already used by Python with g++ and clang++ on all platforms but OpenIndiana.

I think we want a more robust approach here, given the comment https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57025#c4:

the C++ standard allows __STDC_VERSION to be defined by a C++ compiler.

Well, my change fix this exact issue.

@encukou

This comment was marked as outdated.

@encukou

encukou commented Oct 22, 2026

Copy link
Copy Markdown
Member

Correction: turns out my other PR probably won't fix this issue -- that's about the _Py_ANONYMOUS definition, which is not used for the struct in object.h.

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

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 4fe34f2 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F160332%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 Oct 22, 2026
@encukou

encukou commented Oct 23, 2026

Copy link
Copy Markdown
Member

Correction correction: Apparently my other PR will fix the issue, by coincidence. If not we'll work on top of it.
I will close this one. Thank you for the investigation, @mtelka & Victor.

@encukou encukou closed this Oct 23, 2026
@vstinner
vstinner deleted the anonymous branch October 23, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants