Skip to content

Allow anonymous unions in public headers, using _Py_ANONYMOUS #137283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

encukou
Copy link
Member

@encukou encukou commented Jul 31, 2025

We already use an anonymous union for PyObject. This makes the workarounds available in all public headers:

  • MSVC: __pragma(warning(disable: 4201)) (with push/pop). Warning 4201 is specifically for anonymous unions, so let's disable for all of <Python.h>
  • GCC/clang, pedantic old C standards: define _Py_ANONYMOUS as __extension__
  • otherwise, define _Py_ANONYMOUS as nothing

(Note that this is only for public headers -- CPython internals use C11, which has anonymous structs/unions.)

C API WG vote: capi-workgroup/decisions#74

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Can the warning only be silenced for anonymous unions, not for anonymous structs?

Maybe add _Py_ANONYMOUS_UNION, or even _Py_BEGIN_ANONYMOUS_UNION and _Py_END_ANONYMOUS_UNION?

@encukou
Copy link
Member Author

encukou commented Aug 4, 2025

I think that would mean more typing for little benefit.
If you put _Py_ANONYMOUS struct in the headers, tests will fail in strict C++ mode.

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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy