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);
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
Bug report
Bug description:
When compiling a program that links against the Python libraries (and uses their headerfiles) with the
-Werror=declaration-after-statementcompiler flag enabled, the following error occurs: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.
Compiled in either case using:
or equivalently, using
llvmv17:CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs