Skip to content

Commit d776917

Browse files
committed
Check for compiler warnings in test_cext on Windows
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.
1 parent 4999e0b commit d776917

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

Include/pymacro.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
4747
#define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
4848

49-
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
49+
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
50+
&& !defined(_MSC_VER))
5051
# define Py_BUILD_ASSERT_EXPR(cond) \
5152
((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \
5253
0)

Lib/test/test_cext/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def run_cmd(operation, cmd):
8686
cmd = [python_exe, '-X', 'dev',
8787
'-m', 'pip', 'install', '--no-build-isolation',
8888
os.path.abspath(pkg_dir)]
89+
if support.verbose:
90+
cmd.append('-v')
8991
run_cmd('Install', cmd)
9092

9193
# Do a reference run. Until we test that running python

Lib/test/test_cext/setup.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
SOURCE = 'extension.c'
14+
1415
if not support.MS_WINDOWS:
1516
# C compiler flags for GCC and clang
1617
CFLAGS = [
@@ -25,8 +26,11 @@
2526
'-Werror=declaration-after-statement',
2627
)
2728
else:
28-
# Don't pass any compiler flag to MSVC
29-
CFLAGS = []
29+
# MSVC compiler flags
30+
CFLAGS = [
31+
# Treat all compiler warnings as compiler errors
32+
'/WX',
33+
]
3034

3135

3236
def main():

Lib/test/test_cppext/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def run_cmd(operation, cmd):
7676
cmd = [python_exe, '-X', 'dev',
7777
'-m', 'pip', 'install', '--no-build-isolation',
7878
os.path.abspath(pkg_dir)]
79+
if support.verbose:
80+
cmd.append('-v')
7981
run_cmd('Install', cmd)
8082

8183
# Do a reference run. Until we test that running python

Lib/test/test_cppext/setup.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
SOURCE = 'extension.cpp'
13+
1314
if not support.MS_WINDOWS:
1415
# C++ compiler flags for GCC and clang
1516
CPPFLAGS = [
@@ -19,8 +20,11 @@
1920
'-Werror',
2021
]
2122
else:
22-
# Don't pass any compiler flag to MSVC
23-
CPPFLAGS = []
23+
# MSVC compiler flags
24+
CPPFLAGS = [
25+
# Treat all compiler warnings as compiler errors
26+
'/WX',
27+
]
2428

2529

2630
def main():

0 commit comments

Comments
 (0)