Skip to content

object.h:131:16: error: ISO C++ prohibits anonymous structs [-Wpedantic] #160208

Closed

Description

@mtelka

The test_cext test fails on Python 3.14.9 and 3.15.1 with the following error:

  building '_test_cppext' extension
  creating build/temp.solaris-2.11-i86pc.64bit-cpython-315
  /usr/gcc/14/bin/g++ -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -m64 -O3 -g -gdwarf-4 -gstrict-dwarf -msave-args -fno-reorder-functions -fno-reorder-blocks-and-partition -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1 -D_XPG6 -D_REENTRANT -fPIC -I/data/builds/oi-py315/components/python/python-315/build/amd64/build/test_python_154508æ/tempcwd/env/include -I/data/builds/oi-py315/components/python/python-315/Python-3.15.1/Include -I/data/builds/oi-py315/components/python/python-315/build/amd64 -c extension.cpp -o build/temp.solaris-2.11-i86pc.64bit-cpython-315/extension.o -Wall -Wextra -Werror -DMODULE_NAME=_test_cppext -pedantic-errors -Wno-long-long
  In file included from /data/builds/oi-py315/components/python/python-315/Python-3.15.1/Include/Python.h:79,
                   from extension.c:16,
                   from extension.cpp:3:
  /data/builds/oi-py315/components/python/python-315/Python-3.15.1/Include/object.h:131:16: error: ISO C++ prohibits anonymous structs [-Wpedantic]
    131 |         struct {
        |                ^
  error: command '/usr/gcc/14/bin/g++' failed with exit code 1
  error: subprocess-exited-with-error

  × Building wheel for internal__test_cppext (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> No available output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: '/data/builds/oi-py315/components/python/python-315/build/amd64/build/test_python_154508æ/tempcwd/env/bin/python' '/data/builds/oi-py315/components/python/python-315/build/amd64/build/test_python_154508æ/tempcwd/env/lib/python3.15/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py' build_wheel /tmp/test_python_9fsz780f/tmp1lo16wpw
  cwd: /data/builds/oi-py315/components/python/python-315/build/amd64/build/test_python_154508æ/tempcwd/pkg
  Building wheel for internal__test_cppext (pyproject.toml): finished with status 'error'
  ERROR: Failed building wheel for internal__test_cppext
Failed to build internal__test_cppext
error: failed-wheel-build-for-install

Linked PRs

Activity

  1. changed the title [-]object.h:125:16: error: ISO C++ prohibits anonymous structs [-Wpedantic][/-] [+]object.h:131:16: error: ISO C++ prohibits anonymous structs [-Wpedantic][/+] on Oct 22, 2026
  2. added
    type-bugAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    on Oct 22, 2026
  3. added a commit that references this issue on Oct 22, 2026
  4. vstinner commented on Oct 22, 2026

    @vstinner
    Member

    Hi. What is your g++ version and operating system name and version? Can you attach the full test_cext output as a file?

    Can you try attached #160214 to see if it does fix the g++ warning for you?

    I cannot reproduce the issue on Fedora 44 with g++ 16.2.1.

  5. mtelka commented on Oct 22, 2026

    @mtelka
    ContributorAuthor

    OS and version: OpenIndiana Hipster

    $ /usr/gcc/14/bin/g++ --version
    g++ (OpenIndiana 14.3.0-oi-4) 14.3.0
    Copyright (C) 2024 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    $
    

    Full test log: test_cext.log

  6. vstinner commented on Oct 22, 2026

    @vstinner
    Member

    Ok, so two C++ tests using -pedantic-errors option fail:

    • ERROR: test_build (test.test_cext.TestPublicCpp.test_build)
    • ERROR: test_build_limited (test.test_cext.TestPublicCpp.test_build_limited)

    TestInternalCpp doesn't fail since it doesn't use -pedantic-errors (oops, there is a typo in the code, it's written TestInteralCpp).

  7. added 3 commits that reference this issue on Oct 22, 2026
  8. mtelka commented on Oct 22, 2026

    @mtelka
    ContributorAuthor

    With ef524c6:

      building '_test_cppext' extension
      creating build/temp.solaris-2.11-i86pc.64bit-cpython-315
      /usr/gcc/14/bin/g++ -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-strict-overflow -Wsign-compare -DNDEBUG -g -O3 -Wall -m64 -O3 -g -gdwarf-4 -gstrict-dwarf -msave-args -fno-reorder-functions -fno-reorder-blocks-and-partition -D_XOPEN_SOURCE=600 -D__EXTENSIONS__=1 -D_XPG6 -D_REENTRANT -fPIC -I/data/builds/oi-py315/components/python/python-315/build/amd64/build/test_python_199041æ/tempcwd/env/include -I/data/builds/oi-py315/components/python/python-315/Python-3.15.1/Include -I/data/builds/oi-py315/components/python/python-315/build/amd64 -c extension.cpp -o build/temp.solaris-2.11-i86pc.64bit-cpython-315/extension.o -Wall -Wextra -Werror -DMODULE_NAME=_test_cppext -pedantic-errors -Wno-long-long
      In file included from /data/builds/oi-py315/components/python/python-315/Python-3.15.1/Include/Python.h:79,
                       from extension.c:16,
                       from extension.cpp:3:
      /data/builds/oi-py315/components/python/python-315/Python-3.15.1/Include/object.h:131:30: error: ISO C++ prohibits anonymous structs [-Wpedantic]
        131 |         _Py_ANONYMOUS struct {
            |                              ^
      error: command '/usr/gcc/14/bin/g++' failed with exit code 1
      error: subprocess-exited-with-error
    
      × Building wheel for internal__test_cppext (pyproject.toml) did not run successfully.
      │ exit code: 1
      ╰─> No available output.
    
      note: This error originates from a subprocess, and is likely not a problem with pip.
    
  9. vstinner commented on Oct 22, 2026

    @vstinner
    Member

    I can reproduce the issue on OpenIndiana and g++ 14.3.0 with this C++ program:

    //#define _Py_ANONYMOUS __extension__
    #define _Py_ANONYMOUS
    
    struct _object {
        _Py_ANONYMOUS union {
            int ob_refcnt_full;
            struct {
                int ob_refcnt;
                int ob_overflow;
                int ob_flags;
            };
        };
    };

    Example:

    $ g++ -c test.cpp -o test.o -Wall -Wextra -Werror -pedantic-errors 
    z.cpp:9:16: error: ISO C++ prohibits anonymous structs [-Wpedantic]
        9 |         struct {
          |                ^
    

    I can also reproduce the g++ compiler error on Fedora 44 with g++ 16.2.1.


    What's special about OpenIndiana is that C headers like <stdint.h> do define __STDC_VERSION__ macro:

    #include <stdint.h>
    
    #ifdef __STDC_VERSION__
    #  error "__STDC_VERSION__ is defined"
    #else
    #  error "__STDC_VERSION__ is NOT defined"
    #endif

    Output on OpenIndiana (macro defined):

    $ g++ x.cpp -o x
    x.cpp:4:4: error: #error "__STDC_VERSION__ is defined"
        4 | #  error "__STDC_VERSION__ is defined"
          |    ^~~~~
    

    Output on Fedora 44 (macro NOT defined):

    $  g++ x.cpp -o x
    x.cpp:6:4: error: #error "__STDC_VERSION__ is NOT defined"
        6 | #  error "__STDC_VERSION__ is NOT defined"
          |    ^~~~~
    
  10. added 2 commits that reference this issue on Oct 23, 2026
  11. mtelka commented on Oct 23, 2026

    @mtelka
    ContributorAuthor

    @encukou Please note that 3.14 does have the same issue. I'd really appreciate it if 3.14 is fixed too. Thank you.

  12. encukou commented on Oct 23, 2026

    @encukou
    Member

    Please skip the test (or patch this) in your builds. Per PEP 11, we generally don't backport fixes for unsupported platforms to maintenance branches.

    The test failure is harmless (except for building extensions with C++ & -pedantic-errors, which I wouldn't recommend). The test is more of a warning for us about out-of-spec features sneaking into the headers.

  13. mtelka commented on Oct 23, 2026

    @mtelka
    ContributorAuthor

    @encukou okay. Understood. Thank you!

  14. vstinner commented on Oct 24, 2026

    @vstinner
    Member

    I created #160562 to fix PyObject on Python 3.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions