https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81172
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
--- Comment #7 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #6)
> For the slightly modified test case GCC 10 issues the expected warnings in
> the expected cases (i.e., unless the code is removed as unused, etc.) So I
> think this can be resolved as fixed. (There are plenty of other cases that
> still aren't diagnosed; please open new bugs for those if they aren't
> already being tracked under pr56456).
>
> $ cat pr81172.c && gcc -O2 -S -Wall pr81172.c
>
> int a[] = {1,2,3,4};
>
> int* f (void)
> {
> int *p = a + 5;
> return p;
> }
>
> const char s[] = "aaa", t[] = "bbbbb";
>
> const char* g (void)
> {
> const char *p = s + __builtin_strlen (t);
> return p;
> }
>
> const char* h (void)
> {
> return s + 'c';
> }
> pr81172.c: In function ‘f’:
> pr81172.c:5:8: warning: array subscript 5 is outside array bounds of
> ‘int[4]’ [-Warray-bounds]
> 5 | int *p = a + 5;
> | ^
> pr81172.c:1:5: note: while referencing ‘a’
> 1 | int a[] = {1,2,3,4};
> | ^
> pr81172.c: In function ‘g’:
> pr81172.c:13:15: warning: array subscript 5 is outside array bounds of
> ‘const char[4]’ [-Warray-bounds]
> 13 | const char *p = s + __builtin_strlen (t);
> | ^
> pr81172.c:9:12: note: while referencing ‘s’
> 9 | const char s[] = "aaa", t[] = "bbbbb";
> | ^
> pr81172.c: In function ‘h’:
> pr81172.c:19:12: warning: array subscript 99 is outside array bounds of
> ‘const char[4]’ [-Warray-bounds]
> 19 | return s + 'c';
> | ~~^~~~~
> pr81172.c:9:12: note: while referencing ‘s’
> 9 | const char s[] = "aaa", t[] = "bbbbb";
> | ^
I'd think breaking this into a separate sub-option as previously suggested
would still be useful; I can see people wanting other -Warray-bounds warnings
but not these, and vice versa