Check for compiler warnings in test_cext on Windows (#121088)

On Windows, test_cext and test_cppext now pass /WX flag to the MSC
compiler to treat all compiler warnings as errors. In verbose mode,
these tests now log the compiler commands to help debugging.

Change Py_BUILD_ASSERT_EXPR implementation on Windows to avoid a
compiler warning about an unnamed structure.
This commit is contained in:
Victor Stinner 2024-06-28 14:41:37 +02:00 committed by GitHub
parent ef3c400434
commit 43709d5d54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 5 deletions

View file

@ -46,7 +46,8 @@
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */ /* Argument must be a char or an int in [-128, 127] or [0, 255]. */
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff)) #define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
&& !defined(_MSC_VER))
# define Py_BUILD_ASSERT_EXPR(cond) \ # define Py_BUILD_ASSERT_EXPR(cond) \
((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \ ((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \
0) 0)

View file

@ -86,6 +86,8 @@ class TestExt(unittest.TestCase):
cmd = [python_exe, '-X', 'dev', cmd = [python_exe, '-X', 'dev',
'-m', 'pip', 'install', '--no-build-isolation', '-m', 'pip', 'install', '--no-build-isolation',
os.path.abspath(pkg_dir)] os.path.abspath(pkg_dir)]
if support.verbose:
cmd.append('-v')
run_cmd('Install', cmd) run_cmd('Install', cmd)
# Do a reference run. Until we test that running python # Do a reference run. Until we test that running python

View file

@ -11,6 +11,7 @@ from setuptools import setup, Extension
SOURCE = 'extension.c' SOURCE = 'extension.c'
if not support.MS_WINDOWS: if not support.MS_WINDOWS:
# C compiler flags for GCC and clang # C compiler flags for GCC and clang
CFLAGS = [ CFLAGS = [
@ -28,8 +29,11 @@ if not support.MS_WINDOWS:
'-Werror=declaration-after-statement', '-Werror=declaration-after-statement',
) )
else: else:
# Don't pass any compiler flag to MSVC # MSVC compiler flags
CFLAGS = [] CFLAGS = [
# Treat all compiler warnings as compiler errors
'/WX',
]
def main(): def main():

View file

@ -76,6 +76,8 @@ class TestCPPExt(unittest.TestCase):
cmd = [python_exe, '-X', 'dev', cmd = [python_exe, '-X', 'dev',
'-m', 'pip', 'install', '--no-build-isolation', '-m', 'pip', 'install', '--no-build-isolation',
os.path.abspath(pkg_dir)] os.path.abspath(pkg_dir)]
if support.verbose:
cmd.append('-v')
run_cmd('Install', cmd) run_cmd('Install', cmd)
# Do a reference run. Until we test that running python # Do a reference run. Until we test that running python

View file

@ -10,6 +10,7 @@ from setuptools import setup, Extension
SOURCE = 'extension.cpp' SOURCE = 'extension.cpp'
if not support.MS_WINDOWS: if not support.MS_WINDOWS:
# C++ compiler flags for GCC and clang # C++ compiler flags for GCC and clang
CPPFLAGS = [ CPPFLAGS = [
@ -19,8 +20,11 @@ if not support.MS_WINDOWS:
'-Werror', '-Werror',
] ]
else: else:
# Don't pass any compiler flag to MSVC # MSVC compiler flags
CPPFLAGS = [] CPPFLAGS = [
# Treat all compiler warnings as compiler errors
'/WX',
]
def main(): def main():