https://github.com/python/cpython/commit/43709d5d5424725ec061de2c12c3761affde69ef
commit: 43709d5d5424725ec061de2c12c3761affde69ef
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2024-06-28T14:41:37+02:00
summary:

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.

files:
M Include/pymacro.h
M Lib/test/test_cext/__init__.py
M Lib/test/test_cext/setup.py
M Lib/test/test_cppext/__init__.py
M Lib/test/test_cppext/setup.py

diff --git a/Include/pymacro.h b/Include/pymacro.h
index b388c2a4a663ce..a7945ef84a46fc 100644
--- a/Include/pymacro.h
+++ b/Include/pymacro.h
@@ -46,7 +46,8 @@
 /* Argument must be a char or an int in [-128, 127] or [0, 255]. */
 #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) \
     ((void)sizeof(struct { int dummy; _Static_assert(cond, #cond); }), \
      0)
diff --git a/Lib/test/test_cext/__init__.py b/Lib/test/test_cext/__init__.py
index ec44b0ce1f8a56..54859f9ff7622d 100644
--- a/Lib/test/test_cext/__init__.py
+++ b/Lib/test/test_cext/__init__.py
@@ -86,6 +86,8 @@ def run_cmd(operation, cmd):
         cmd = [python_exe, '-X', 'dev',
                '-m', 'pip', 'install', '--no-build-isolation',
                os.path.abspath(pkg_dir)]
+        if support.verbose:
+            cmd.append('-v')
         run_cmd('Install', cmd)
 
         # Do a reference run. Until we test that running python
diff --git a/Lib/test/test_cext/setup.py b/Lib/test/test_cext/setup.py
index 383d256c1eb53b..19edc5e663c55d 100644
--- a/Lib/test/test_cext/setup.py
+++ b/Lib/test/test_cext/setup.py
@@ -11,6 +11,7 @@
 
 
 SOURCE = 'extension.c'
+
 if not support.MS_WINDOWS:
     # C compiler flags for GCC and clang
     CFLAGS = [
@@ -28,8 +29,11 @@
             '-Werror=declaration-after-statement',
         )
 else:
-    # Don't pass any compiler flag to MSVC
-    CFLAGS = []
+    # MSVC compiler flags
+    CFLAGS = [
+        # Treat all compiler warnings as compiler errors
+        '/WX',
+    ]
 
 
 def main():
diff --git a/Lib/test/test_cppext/__init__.py b/Lib/test/test_cppext/__init__.py
index 00a2840d49c779..efd79448c66104 100644
--- a/Lib/test/test_cppext/__init__.py
+++ b/Lib/test/test_cppext/__init__.py
@@ -76,6 +76,8 @@ def run_cmd(operation, cmd):
         cmd = [python_exe, '-X', 'dev',
                '-m', 'pip', 'install', '--no-build-isolation',
                os.path.abspath(pkg_dir)]
+        if support.verbose:
+            cmd.append('-v')
         run_cmd('Install', cmd)
 
         # Do a reference run. Until we test that running python
diff --git a/Lib/test/test_cppext/setup.py b/Lib/test/test_cppext/setup.py
index 80b3e0d5212f7b..f1848f2fd42a46 100644
--- a/Lib/test/test_cppext/setup.py
+++ b/Lib/test/test_cppext/setup.py
@@ -10,6 +10,7 @@
 
 
 SOURCE = 'extension.cpp'
+
 if not support.MS_WINDOWS:
     # C++ compiler flags for GCC and clang
     CPPFLAGS = [
@@ -19,8 +20,11 @@
         '-Werror',
     ]
 else:
-    # Don't pass any compiler flag to MSVC
-    CPPFLAGS = []
+    # MSVC compiler flags
+    CPPFLAGS = [
+        # Treat all compiler warnings as compiler errors
+        '/WX',
+    ]
 
 
 def main():

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to