Skip to content

Commit ca69278

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 ca69278

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/pybind11/pybind11.h

+10
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,17 @@ 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 these warnings are disabled as they trigger
1387+
// false positive warnings. Discussed here:
1388+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115824.
1389+
PYBIND11_WARNING_DISABLE_GCC("-Warray-bounds")
1390+
PYBIND11_WARNING_DISABLE_GCC("-Wstringop-overread")
1391+
#endif
13831392
internals.registered_types_py[(PyTypeObject *) m_ptr] = {tinfo};
1393+
PYBIND11_WARNING_POP
13841394
});
13851395

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

0 commit comments

Comments
 (0)