https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84051

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
I see GCC warns for this case with -Warray-bounds=2 and it's being tested in
gcc.dg/Warray-bounds-11.c.

I think it would make sense to warn on the pointer to array case even at level
1.  It seems quite unlikely for a pointer to an array of a known bound to be
set to point to a larger array and used to access elements beyond that bound.

Separately, I also wonder if it would make sense to warn for out-of-bounds
accesses to trailing arrays with more than 1 element.  Those too seem unlikely,
and the recommendation is to use either flexible array members or zero-length
arrays for such things.

By warning on these cases GCC would help detect more bugs and encourage working
code to migrate to the recommended solutions.

Perhaps for GCC 10.

Reply via email to