Skip to content

Commit 1bcaac6

Browse files
committed
test_cppext: Enable -pedantic-errors under GCC & clang
1 parent 7a312ff commit 1bcaac6

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Lib/test/test_cppext/extension.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,24 @@ class VirtualPyObject : public PyObject {
161161

162162
int VirtualPyObject::instance_count = 0;
163163

164+
// Converting from function pointer to void* has undefined behavior, but
165+
// works on all known platforms, and CPython's module and type slots currently
166+
// need it.
167+
// (GCC doesn't have a narrower category for this than -Wpedantic.)
168+
_Py_COMP_DIAG_PUSH
169+
#if defined(__GNUC__)
170+
#pragma GCC diagnostic ignored "-Wpedantic"
171+
#elif defined(__clang__)
172+
#pragma clang diagnostic ignored "-Wpedantic"
173+
#endif
174+
164175
PyType_Slot VirtualPyObject_Slots[] = {
165176
{Py_tp_free, (void*)VirtualPyObject::dealloc},
166177
{0, _Py_NULL},
167178
};
168179

180+
_Py_COMP_DIAG_POP
181+
169182
PyType_Spec VirtualPyObject_Spec = {
170183
/* .name */ STR(MODULE_NAME) ".VirtualPyObject",
171184
/* .basicsize */ sizeof(VirtualPyObject),
@@ -241,11 +254,20 @@ _testcppext_exec(PyObject *module)
241254
return 0;
242255
}
243256

257+
// Need to ignore "-Wpedantic" warnings; see VirtualPyObject_Slots above
258+
_Py_COMP_DIAG_PUSH
259+
#if defined(__GNUC__)
260+
#pragma GCC diagnostic ignored "-Wpedantic"
261+
#elif defined(__clang__)
262+
#pragma clang diagnostic ignored "-Wpedantic"
263+
#endif
264+
244265
static PyModuleDef_Slot _testcppext_slots[] = {
245266
{Py_mod_exec, reinterpret_cast<void*>(_testcppext_exec)},
246267
{0, _Py_NULL}
247268
};
248269

270+
_Py_COMP_DIAG_POP
249271

250272
PyDoc_STRVAR(_testcppext_doc, "C++ test extension.");
251273

Lib/test/test_cppext/setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
# a C++ extension using the Python C API does not emit C++ compiler
1919
# warnings
2020
'-Werror',
21+
22+
# Ask for strict(er) compliance with the standard.
23+
'-pedantic-errors',
24+
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',
2129
]
2230
else:
2331
# MSVC compiler flags

0 commit comments

Comments
 (0)