Skip to content

Commit cd933d2

Browse files
committed
Add workaround/fix 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 in this discussion.
1 parent 8a801bd commit cd933d2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

include/pybind11/pybind11.h

+12
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,19 @@ class generic_type : public object {
13801380
} else {
13811381
internals.registered_types_cpp[tindex] = tinfo;
13821382
}
1383+
// The following `GCC diagnostic` pragmas are used to suppress
1384+
// warnings about out-of-bounds array access in the following
1385+
// code. The warnings are false positives. This bug affects GCC 12.
1386+
//
1387+
// This is discussed here:
1388+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115824.
1389+
//
1390+
// The following fix is based on the the suggested workaround:
1391+
#pragma GCC diagnostic push
1392+
#pragma GCC diagnostic ignored "-Warray-bounds"
1393+
#pragma GCC diagnostic ignored "-Wstringop-overread"
13831394
internals.registered_types_py[(PyTypeObject *) m_ptr] = {tinfo};
1395+
#pragma GCC diagnostic pop
13841396
});
13851397

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

0 commit comments

Comments
 (0)