Skip to content

Commit 0d6e657

Browse files
[3.12] gh-105776: Fix test_cppext when CC contains -std=c11 option (GH-108343) (#108345)
gh-105776: Fix test_cppext when CC contains -std=c11 option (GH-108343) Fix test_cppext when the C compiler command has the "-std=c11" option. Remove "-std=" options from the compiler command. (cherry picked from commit 9173b2b) Co-authored-by: Victor Stinner <[email protected]>
1 parent 61dbf46 commit 0d6e657

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Lib/test/test_cppext/setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# gh-91321: Build a basic C++ test extension to check that the Python C API is
22
# compatible with C++ and does not emit C++ compiler warnings.
33
import os
4+
import shlex
45
import sys
6+
import sysconfig
57

68
from setuptools import setup, Extension
79

@@ -30,6 +32,17 @@ def main():
3032

3133
cppflags = [*CPPFLAGS, f'-std={std}']
3234

35+
# gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11
36+
# option emits a C++ compiler warning. Remove "-std11" option from the
37+
# CC command.
38+
cmd = (sysconfig.get_config_var('CC') or '')
39+
if cmd is not None:
40+
cmd = shlex.split(cmd)
41+
cmd = [arg for arg in cmd if not arg.startswith('-std=')]
42+
cmd = shlex.join(cmd)
43+
# CC env var overrides sysconfig CC variable in setuptools
44+
os.environ['CC'] = cmd
45+
3346
cpp_ext = Extension(
3447
name,
3548
sources=[SOURCE],
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix test_cppext when the C compiler command ``-std=c11`` option: remove
2+
``-std=`` options from the compiler command. Patch by Victor Stinner.

0 commit comments

Comments
 (0)