Skip to content

Commit

Permalink
Add workaround/fix for GGC 12 bound checking error
Browse files Browse the repository at this point in the history
Issue: pybind#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.
  • Loading branch information
BobbyRBruce committed Sep 8, 2024
1 parent 8a801bd commit c14d070
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,23 @@ class generic_type : public object {
} else {
internals.registered_types_cpp[tindex] = tinfo;
}
#if defined(__GNUG__) && __GNUC__ == 12
// 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:
PYBIND11_WARNING_PUSH
PYBIND11_WARNING_DISABLE_GCC("-Wdarray-bounds")
PYBIND11_WARNING_DISABLE_GCC("-Wstringop-overread")
#endif
internals.registered_types_py[(PyTypeObject *) m_ptr] = {tinfo};
#if defined(__GNUG__) && __GNUC__ == 12
PYBIND11_WARNING_POP
#endif
});

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

0 comments on commit c14d070

Please sign in to comment.