Skip to content

Commit 02c1292

Browse files
committed
Add warn disable for GGC 12 bound checking error
Issue: #5224 The `internals.registered_types_py...` line in pybind11.h triggers a false-positive bounds checking warning in GCC 12. This is discussed in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115824. The workaround implemented is taken from suggestions then refactored to use the `PYBIND11_WARNING_PUSH` and `PYBIND11_WARNING_POP` MACROS.
1 parent 8a801bd commit 02c1292

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

include/pybind11/pybind11.h

+14
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,21 @@ class generic_type : public object {
13801380
} else {
13811381
internals.registered_types_cpp[tindex] = tinfo;
13821382
}
1383+
1384+
PYBIND11_WARNING_PUSH
1385+
#if defined(__GNUC__) && __GNUC__ == 12
1386+
// When using GCC 12 the `array-bounds` and `stringop-overread`
1387+
// warnings are disabled as they trigger false positive warnings.
1388+
//
1389+
// This is a known GCC 12 issue and is discussed here:
1390+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115824. This
1391+
// solution is based on advice given in this discussion but
1392+
// refactored with `PYBIND11_WARNING_DISABLE_GCC` MACRO.
1393+
PYBIND11_WARNING_DISABLE_GCC("-Warray-bounds")
1394+
PYBIND11_WARNING_DISABLE_GCC("-Wstringop-overread")
1395+
#endif
13831396
internals.registered_types_py[(PyTypeObject *) m_ptr] = {tinfo};
1397+
PYBIND11_WARNING_POP
13841398
});
13851399

13861400
if (rec.bases.size() > 1 || rec.multiple_inheritance) {

0 commit comments

Comments
 (0)