-Warray-bounds -Warray-bounds=n This option is only active when -ftree-vrp is active (default for -O2 and above). It warns about subscripts to arrays that are always out of bounds. This warning is enabled by -Wall. It's not true that it warns for "always out of bounds", as that implies no false positives.
Confirmed.
The documentation is also incorrect about the warning being only active with -ftree-vrp. A small subset of -Warray-bounds is issued even without optimization. For example the following warning(s) have been issued since GCC 4.1: $ cat a.c && gcc -S -Wall a.c int f (void) { return __builtin_strlen ("123" + 5); } a.c: In function ‘f’: a.c:3:34: warning: offset ‘5’ outside bounds of constant string [-Warray-bounds] 3 | return __builtin_strlen ("123" + 5); | ~~~~~~^~~ a.c:3:10: warning: offset ‘5’ outside bounds of constant string [-Warray-bounds] 3 | return __builtin_strlen ("123" + 5); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let me update the manual.
Patch: https://gcc.gnu.org/pipermail/gcc-patches/2022-February/590233.html
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>: https://gcc.gnu.org/g:7a1b179b08bc802280ca90ed4c6c8d8b25503e66 commit r12-7234-g7a1b179b08bc802280ca90ed4c6c8d8b25503e66 Author: Martin Sebor <msebor@redhat.com> Date: Mon Feb 14 15:40:25 2022 -0700 Update -Warray-bounds documentation [PR104355]. Resolves: PR middle-end/104355 - Misleading and outdated -Warray-bounds documentation gcc/ChangeLog: PR middle-end/104355 * doc/invoke.texi (-Warray-bounds): Update documentation.
Looks like this was fixed by Martin's commit 2 years ago, closing now.