Skip to content

Commit a7910be

Browse files
authored
Add warn disable for GGC 12 bound checking error (#5355)
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 0cf3a0f commit a7910be

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
@@ -1382,7 +1382,17 @@ class generic_type : public object {
13821382
} else {
13831383
internals.registered_types_cpp[tindex] = tinfo;
13841384
}
1385+
1386+
PYBIND11_WARNING_PUSH
1387+
#if defined(__GNUC__) && __GNUC__ == 12
1388+
// When using GCC 12 these warnings are disabled as they trigger
1389+
// false positive warnings. Discussed here:
1390+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115824.
1391+
PYBIND11_WARNING_DISABLE_GCC("-Warray-bounds")
1392+
PYBIND11_WARNING_DISABLE_GCC("-Wstringop-overread")
1393+
#endif
13851394
internals.registered_types_py[(PyTypeObject *) m_ptr] = {tinfo};
1395+
PYBIND11_WARNING_POP
13861396
});
13871397

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

0 commit comments

Comments
 (0)