diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 1806583e6b..94b02cb6e5 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1380,7 +1380,19 @@ class generic_type : public object { } else { internals.registered_types_cpp[tindex] = tinfo; } + // The following `GCC diagnostic` pragmas are used to suppress +// warnings about out-of-bounds array access in the following +// code. The warnings are false positives. This bug affects GCC 12. +// +// This is discussed here: +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115824. +// +// The following fix is based on the the suggested workaround: +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#pragma GCC diagnostic ignored "-Wstringop-overread" internals.registered_types_py[(PyTypeObject *) m_ptr] = {tinfo}; +#pragma GCC diagnostic pop }); if (rec.bases.size() > 1 || rec.multiple_inheritance) {