mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-129666: Add C11/C++11 to docs and -pedantic-errors
to GCC/clang test_c[pp]ext tests (GH-130686)
This commit is contained in:
parent
cc17307faa
commit
003e6d2b97
7 changed files with 62 additions and 0 deletions
|
@ -29,6 +29,9 @@ class TestCPPExt(unittest.TestCase):
|
|||
self.check_build('_testcppext')
|
||||
|
||||
def test_build_cpp03(self):
|
||||
# In public docs, we say C API is compatible with C++11. However,
|
||||
# in practice we do maintain C++03 compatibility in public headers.
|
||||
# Please ask the C API WG before adding a new C++11-only feature.
|
||||
self.check_build('_testcpp03ext', std='c++03')
|
||||
|
||||
@unittest.skipIf(support.MS_WINDOWS, "MSVC doesn't support /std:c++11")
|
||||
|
|
|
@ -161,11 +161,24 @@ private:
|
|||
|
||||
int VirtualPyObject::instance_count = 0;
|
||||
|
||||
// Converting from function pointer to void* has undefined behavior, but
|
||||
// works on all known platforms, and CPython's module and type slots currently
|
||||
// need it.
|
||||
// (GCC doesn't have a narrower category for this than -Wpedantic.)
|
||||
_Py_COMP_DIAG_PUSH
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic ignored "-Wpedantic"
|
||||
#endif
|
||||
|
||||
PyType_Slot VirtualPyObject_Slots[] = {
|
||||
{Py_tp_free, (void*)VirtualPyObject::dealloc},
|
||||
{0, _Py_NULL},
|
||||
};
|
||||
|
||||
_Py_COMP_DIAG_POP
|
||||
|
||||
PyType_Spec VirtualPyObject_Spec = {
|
||||
/* .name */ STR(MODULE_NAME) ".VirtualPyObject",
|
||||
/* .basicsize */ sizeof(VirtualPyObject),
|
||||
|
@ -241,11 +254,20 @@ _testcppext_exec(PyObject *module)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Need to ignore "-Wpedantic" warnings; see VirtualPyObject_Slots above
|
||||
_Py_COMP_DIAG_PUSH
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic ignored "-Wpedantic"
|
||||
#endif
|
||||
|
||||
static PyModuleDef_Slot _testcppext_slots[] = {
|
||||
{Py_mod_exec, reinterpret_cast<void*>(_testcppext_exec)},
|
||||
{0, _Py_NULL}
|
||||
};
|
||||
|
||||
_Py_COMP_DIAG_POP
|
||||
|
||||
PyDoc_STRVAR(_testcppext_doc, "C++ test extension.");
|
||||
|
||||
|
|
|
@ -18,6 +18,14 @@ if not support.MS_WINDOWS:
|
|||
# a C++ extension using the Python C API does not emit C++ compiler
|
||||
# warnings
|
||||
'-Werror',
|
||||
|
||||
# Ask for strict(er) compliance with the standard.
|
||||
'-pedantic-errors',
|
||||
|
||||
# But allow C++11 features for -std=C++03. We use:
|
||||
# - `long long` (-Wno-c++11-long-long)
|
||||
# - comma at end of `enum` lists (no narrower GCC option exists)
|
||||
'-Wno-c++11-extensions',
|
||||
]
|
||||
else:
|
||||
# MSVC compiler flags
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue