https://github.com/python/cpython/commit/b22a8c9fd44855d7cc013eb49f689dfd396639a7
commit: b22a8c9fd44855d7cc013eb49f689dfd396639a7
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-08T03:26:19+02:00
summary:

gh-149044: Build test_cext with -Wall -Wextra (#158867)

files:
M Lib/test/test_cext/setup.py

diff --git a/Lib/test/test_cext/setup.py b/Lib/test/test_cext/setup.py
index c5706d23748e53..10a3887931932a 100644
--- a/Lib/test/test_cext/setup.py
+++ b/Lib/test/test_cext/setup.py
@@ -21,6 +21,8 @@
 if not MSVC:
     # C compiler flags for GCC and clang
     BASE_CFLAGS = [
+        '-Wall',
+        '-Wextra',
         # The purpose of test_cext extension is to check that building a C
         # extension using the Python C API does not emit C compiler warnings.
         '-Werror',
@@ -47,7 +49,11 @@
             # with the -Werror=declaration-after-statement compiler flag.
             '-Werror=declaration-after-statement',
         )
-    INTERNAL_CFLAGS = [*BASE_CFLAGS]
+    INTERNAL_CFLAGS = [
+        *BASE_CFLAGS,
+        # Do not complain about unused parameteres in the internal C API
+        '-Wno-unused-parameter',
+    ]
 else:
     # MSVC compiler flags
     BASE_CFLAGS = [
@@ -70,14 +76,16 @@
 
 if not MSVC:
     # C++ compiler flags for GCC and clang
-    CPPFLAGS = [
+    CXXFLAGS = [
+        '-Wall',
+        '-Wextra',
         # gh-91321: The purpose of _testcppext extension is to check that 
building
         # a C++ extension using the Python C API does not emit C++ compiler
         # warnings
         '-Werror',
     ]
 
-    CPPFLAGS_PEDANTIC = [
+    PEDANTIC_CXXFLAGS = [
         # Ask for strict(er) compliance with the standard.
         # We cannot do this for c++03 unlimited API, since several headers in
         # Include/cpython/ use commas at end of `enum` declarations, a C++11
@@ -87,15 +95,20 @@
         # We also use `long long`, a C++11 feature we can enable individually.
         '-Wno-long-long',
     ]
+    INTERNAL_CXXFLAGS = [
+        # Do not complain about unused parameteres in the internal C API
+        '-Wno-unused-parameter',
+    ]
 else:
     # MSVC compiler flags
-    CPPFLAGS = [
+    CXXFLAGS = [
         # Display warnings level 1 to 4
         '/W4',
         # Treat all compiler warnings as compiler errors
         '/WX',
     ]
-    CPPFLAGS_PEDANTIC = []
+    PEDANTIC_CXXFLAGS = []
+    INTERNAL_CXXFLAGS = []
 
 
 def main():
@@ -109,10 +122,13 @@ def main():
     libdirs = os.environ.get("CPYTHON_TEST_EXTRA_LIBDIRS", "")
     extra_cflags = os.environ.get("CPYTHON_TEST_EXTRA_CFLAGS", "")
 
+    if language not in ('C', 'C++'):
+        raise ValueError(f"invalid language: {language}")
+
     source = SOURCE[language]
 
     if language == 'C++':
-        flags = list(CPPFLAGS)
+        flags = list(CXXFLAGS)
     else:
         if not internal:
             flags = list(PUBLIC_CFLAGS)
@@ -127,9 +143,13 @@ def main():
         else:
             flags.append(f'-std={std}')
 
-    if language == 'C++' and (limited or (std != 'c++03') and not internal):
-        # See CPPFLAGS_PEDANTIC docstring
-        flags.extend(CPPFLAGS_PEDANTIC)
+    if language == 'C++':
+        if limited or (std != 'c++03') and not internal:
+            # See PEDANTIC_CXXFLAGS comment
+            flags.extend(PEDANTIC_CXXFLAGS)
+        elif internal:
+            flags.extend(INTERNAL_CXXFLAGS)
+
 
     # gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11
     # option emits a C++ compiler warning. Remove "-std11" option from the

_______________________________________________
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