Skip to content

Commit 6c714df

Browse files
committed
Disable pedantic check for c++03 (unlimited API)
Also add a check for c++03 *limited* API, which passes in pedantic mode after removing a comma in the `PySendResult` declaration, and allowing `long long`.
1 parent 72f4dc2 commit 6c714df

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Include/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
683683
typedef enum {
684684
PYGEN_RETURN = 0,
685685
PYGEN_ERROR = -1,
686-
PYGEN_NEXT = 1,
686+
PYGEN_NEXT = 1
687687
} PySendResult;
688688
#endif
689689

Lib/test/test_cppext/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def test_build_cpp03(self):
3434
# Please ask the C API WG before adding a new C++11-only feature.
3535
self.check_build('_testcpp03ext', std='c++03')
3636

37+
@support.requires_gil_enabled('incompatible with Free Threading')
38+
def test_build_limited_cpp03(self):
39+
self.check_build('_test_limited_cpp03ext', std='c++03', limited=True)
40+
3741
@unittest.skipIf(support.MS_WINDOWS, "MSVC doesn't support /std:c++11")
3842
def test_build_cpp11(self):
3943
self.check_build('_testcpp11ext', std='c++11')

Lib/test/test_cppext/setup.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818
# a C++ extension using the Python C API does not emit C++ compiler
1919
# warnings
2020
'-Werror',
21+
]
2122

23+
CPPFLAGS_PEDANTIC = [
2224
# Ask for strict(er) compliance with the standard.
25+
# We cannot do this for c++03 unlimited API, since several headers in
26+
# Include/cpython/ use commas at end of `enum` declarations, a C++11
27+
# feature for which GCC has no narrower option than -Wpedantic itself.
2328
'-pedantic-errors',
2429

25-
# But allow C++11 features for -std=C++03. We use:
26-
# - `long long` (-Wno-c++11-long-long)
27-
# - comma at end of `enum` lists (no narrower GCC option exists)
28-
'-Wno-c++11-extensions',
30+
# We also use `long long`, a C++11 feature we can enable individually.
31+
'-Wno-long-long',
2932
]
3033
else:
3134
# MSVC compiler flags
@@ -35,6 +38,7 @@
3538
# Treat all compiler warnings as compiler errors
3639
'/WX',
3740
]
41+
CPPFLAGS_PEDANTIC = []
3842

3943

4044
def main():
@@ -53,6 +57,10 @@ def main():
5357
else:
5458
cppflags.append(f'-std={std}')
5559

60+
if limited or (std != 'c++03'):
61+
# See CPPFLAGS_PEDANTIC docstring
62+
cppflags.extend(CPPFLAGS_PEDANTIC)
63+
5664
# gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11
5765
# option emits a C++ compiler warning. Remove "-std11" option from the
5866
# CC command.

0 commit comments

Comments
 (0)