Requiring compilers' C11 standard mode to build CPython

Latest MSVC in C mode with -W4 argument raises four warnings from our headers:

> cl /c /I(python3.12 -c "import sysconfig; print(sysconfig.get_config_var('INCLUDEPY'), end='')") /W4 .\t.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32619.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

t.c
...\Include\object.h(173): warning C4201: nonstandard extension used: nameless struct/union
...\Include\cpython/unicodeobject.h(203): warning C4100: '_unused_op': unreferenced formal parameter
...\Include\cpython/unicodeobject.h(393): warning C4100: '_unused_op': unreferenced formal parameter
...\Include\cpython/pytime.h(192): warning C4115: 'timeval': named type definition in parentheses

Latest MSVC with Microsoft extensions disabled produces 7 (few repeats):

> cl /c /I(python3.12 -c "import sysconfig; print(sysconfig.get_config_var('INCLUDEPY'), end='')") /Za .\t.c
...\Include\object.h(173): error C2467: illegal declaration of anonymous 'union'
...\Include\pycapsule.h(31): warning C4224: nonstandard extension used: formal parameter 'destruct
or' was previously defined as a type
...\Include\pycapsule.h(45): warning C4224: nonstandard extension used: formal parameter 'destruct
or' was previously defined as a type
...\Include\cpython/pytime.h(192): warning C4115: 'timeval': named type definition in parentheses
...\Include\cpython/pytime.h(198): warning C4115: 'timeval': named type definition in parentheses
...\Include\cpython/abstract.h(100): error C2097: illegal initialization
...\Include\cpython/abstract.h(148): error C2097: illegal initialization

For apps that build with all warnings as errors, this makes CPython unusable.

Enabling /std:c11 (which changes the behaviour of my entire program, not just the CPython headers :fearful: ) only fixes the one /W4 warning about anonymous unions, as well as forcing my hand on Microsoft extensions (didn’t check which direction, but I can’t use /Za /std:c11 to disable them, which means they’re either permanently disabled or enabled).

C++ mode doesn’t produce the anonymous union warnings, but it does produce the unreferenced parameter warnings.

/Wall is flooded with struct padding and discarded static inline functions (mostly ours), but if you disable those two warnings you only get unreferenced parameters and a few mismatched signed/unsigned types.

> cl /c /I(python3.12 -c "import sysconfig; print(sysconfig.get_config_var('INCLUDEPY'), end='')") /std:c++14 /Wall /wd4514 /wd4820 .\t.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.37.32619.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

t.cpp
...\Include\cpython/unicodeobject.h(203): warning C4100: '_unused_op': unreferenced formal parameter
...\Include\cpython/unicodeobject.h(343): warning C4365: '=': conversion from 'unsigned int' to 'int', signed/unsigned mismatch
...\Include\cpython/unicodeobject.h(367): warning C4365: '=': conversion from 'unsigned int' to 'int', signed/unsigned mismatch
...\Include\cpython/unicodeobject.h(393): warning C4100: '_unused_op': unreferenced formal parameter
...\Include\cpython/longintrepr.h(121): warning C4365: 'initializing': conversion from 'uintptr_t' to 'Py_ssize_t', signed/unsigned mismatch
...\Include\cpython/abstract.h(60): warning C4365: 'return': conversion from 'size_t' to 'Py_ssize_t', signed/unsigned mismatch

Obviously enabling /WX is going to break these users entirely, and if I cared enough about correctness to enable this (which I do in some cases), I wouldn’t be comfortable with disabling the relevant warnings across my entire application. I’d fork and patch the header files.


So my summary here is that we are impacting users who care about warnings, and are unwilling/unable to change the language of their entire project to accommodate one of our implementation details.

2 Likes