2121if not MSVC :
2222 # C compiler flags for GCC and clang
2323 BASE_CFLAGS = [
24+ '-Wall' ,
25+ '-Wextra' ,
2426 # The purpose of test_cext extension is to check that building a C
2527 # extension using the Python C API does not emit C compiler warnings.
2628 '-Werror' ,
4749 # with the -Werror=declaration-after-statement compiler flag.
4850 '-Werror=declaration-after-statement' ,
4951 )
50- INTERNAL_CFLAGS = [* BASE_CFLAGS ]
52+ INTERNAL_CFLAGS = [
53+ * BASE_CFLAGS ,
54+ # Do not complain about unused parameteres in the internal C API
55+ '-Wno-unused-parameter' ,
56+ ]
5157else :
5258 # MSVC compiler flags
5359 BASE_CFLAGS = [
7076
7177if not MSVC :
7278 # C++ compiler flags for GCC and clang
73- CPPFLAGS = [
79+ CXXFLAGS = [
80+ '-Wall' ,
81+ '-Wextra' ,
7482 # gh-91321: The purpose of _testcppext extension is to check that building
7583 # a C++ extension using the Python C API does not emit C++ compiler
7684 # warnings
7785 '-Werror' ,
7886 ]
7987
80- CPPFLAGS_PEDANTIC = [
88+ PEDANTIC_CXXFLAGS = [
8189 # Ask for strict(er) compliance with the standard.
8290 # We cannot do this for c++03 unlimited API, since several headers in
8391 # Include/cpython/ use commas at end of `enum` declarations, a C++11
8795 # We also use `long long`, a C++11 feature we can enable individually.
8896 '-Wno-long-long' ,
8997 ]
98+ INTERNAL_CXXFLAGS = [
99+ # Do not complain about unused parameteres in the internal C API
100+ '-Wno-unused-parameter' ,
101+ ]
90102else :
91103 # MSVC compiler flags
92- CPPFLAGS = [
104+ CXXFLAGS = [
93105 # Display warnings level 1 to 4
94106 '/W4' ,
95107 # Treat all compiler warnings as compiler errors
96108 '/WX' ,
97109 ]
98- CPPFLAGS_PEDANTIC = []
110+ PEDANTIC_CXXFLAGS = []
111+ INTERNAL_CXXFLAGS = []
99112
100113
101114def main ():
@@ -109,10 +122,13 @@ def main():
109122 libdirs = os .environ .get ("CPYTHON_TEST_EXTRA_LIBDIRS" , "" )
110123 extra_cflags = os .environ .get ("CPYTHON_TEST_EXTRA_CFLAGS" , "" )
111124
125+ if language not in ('C' , 'C++' ):
126+ raise ValueError (f"invalid language: { language } " )
127+
112128 source = SOURCE [language ]
113129
114130 if language == 'C++' :
115- flags = list (CPPFLAGS )
131+ flags = list (CXXFLAGS )
116132 else :
117133 if not internal :
118134 flags = list (PUBLIC_CFLAGS )
@@ -127,9 +143,13 @@ def main():
127143 else :
128144 flags .append (f'-std={ std } ' )
129145
130- if language == 'C++' and (limited or (std != 'c++03' ) and not internal ):
131- # See CPPFLAGS_PEDANTIC docstring
132- flags .extend (CPPFLAGS_PEDANTIC )
146+ if language == 'C++' :
147+ if limited or (std != 'c++03' ) and not internal :
148+ # See PEDANTIC_CXXFLAGS comment
149+ flags .extend (PEDANTIC_CXXFLAGS )
150+ elif internal :
151+ flags .extend (INTERNAL_CXXFLAGS )
152+
133153
134154 # gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11
135155 # option emits a C++ compiler warning. Remove "-std11" option from the
0 commit comments