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: #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 in this discussion.
  • Loading branch information
BobbyRBruce committed Sep 5, 2024
1 parent 8a801bd commit cd933d2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit cd933d2

Please sign in to comment.