Skip to content

Python 3.12.2 headers contain non-C90-compliant code #116869

Closed
@jayaddison

Description

@jayaddison

Bug report

Bug description:

When compiling a program that links against the Python libraries (and uses their headerfiles) with the -Werror=declaration-after-statement compiler flag enabled, the following error occurs:

/usr/include/python3.12/object.h:233:5: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
  233 |     PyVarObject *var_ob = _PyVarObject_CAST(ob);

This is fairly similar to previous issue #92781.

Although the C90 style may be archaic and perhaps not worth supporting at some point, maintaining support could be helpful for some downstream platforms (I encountered this in Debian bug #1057442).

Minimal test cases to show that the problem did not occur with Python 3.11.8 and that it does occur on Python 3.12.2 and to help verify any fixes.
#include "/usr/include/python3.11/Python.h"
#include "/usr/include/python3.11/object.h"

int main() {}
#include "/usr/include/python3.12/Python.h"
#include "/usr/include/python3.12/object.h"

int main() {}

Compiled in either case using:

$ gcc bugreport.c -Werror=declaration-after-statement

or equivalently, using llvm v17:

$ clang-17 bugreport.c -Werror=declaration-after-statement

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions