Skip to content

Commit 1aff195

Browse files
authored
[3.11] gh-105776: Fix test_cppext when CC contains -std=c11 option (#108343) (#108347)
gh-105776: Fix test_cppext when CC contains -std=c11 option (#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)
1 parent a153961 commit 1aff195

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Lib/test/test_cppext/setup.py

+13
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.path
4+
import shlex
45
import sys
6+
import sysconfig
57

68
from setuptools import setup, Extension
79

@@ -36,6 +38,17 @@ def main():
3638

3739
cppflags = [*CPPFLAGS, f'-std={std}']
3840

41+
# gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11
42+
# option emits a C++ compiler warning. Remove "-std11" option from the
43+
# CC command.
44+
cmd = (sysconfig.get_config_var('CC') or '')
45+
if cmd is not None:
46+
cmd = shlex.split(cmd)
47+
cmd = [arg for arg in cmd if not arg.startswith('-std=')]
48+
cmd = shlex.join(cmd)
49+
# CC env var overrides sysconfig CC variable in setuptools
50+
os.environ['CC'] = cmd
51+
3952
cpp_ext = Extension(
4053
name,
4154
sources=[SOURCE],
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)