Below is what I found digging through the GCC Bugzilla and the GCC sources themselves. In short, there is discussion in Bugzilla, but the consensus is that this is “by design,” not a mistake in the warning‐emitter—static objects simply aren’t fed through the same bounds‐analysis pipeline as automatic (stack) objects.
Search Bugzilla for “Warray‐bounds static”
• https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=Warray-bounds+static
You’ll see a handful of reports like
– Bug 24445 “False negative -Warray-bounds with static arrays”
– Bug 81208 “-Warray-bounds does not warn on static arrays”
– Bug 83623 “array-bounds should also cover objects with static storage duration”
What the bugs say
– Bug 24445 (2006) was the first report. Summary: “If you do pointer arithmetic that walks off the end of a static array, -Warray-bounds doesn’t fire.”
– Discussion quickly reveals that the bounds checker in GCC only analyzes arrays it considers “small, local, auto-storage” objects. Static‐storage objects live in a different segment, and the checker was never written to follow them.
– The various later reports are marked WONTFIX or WORKSFORME with the comment “this is a limitation of the current bounds-analysis pass.”
Glimpse at the source
In
gcc/warning.c
you’ll find the routine that implements -Warray-bounds. Early on it does something like:
if ( tree_static (base_decl) )
return false;
i.e. “if this is a static or extern object, bail out.” There’s no warning path for it, so you get silence.
Why “by design”?
– Static objects can live anywhere in the big data segment, possibly adjacent to other objects, so simple “pointer + big constant” isn’t necessarily bogus.
– Including them would have meant a lot more complexity (and false positives) in the analysis.
Bottom line
There are Bugzilla reports (24445, 81208, 83623, …), but all have essentially been closed as “known limitation.” If you want GCC to warn on static arrays, the only recourse is to file a new enhancement request on Bugzilla and argue for extending -Warray-bounds to static‐storage objects.