https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100430
Bug ID: 100430 Summary: False positive for -Warray-bounds and pointers Product: gcc Version: 11.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jens.maurer at gmx dot net Target Milestone: --- This code triggers a -Warray-bounds warning in gcc 11.1 (gcc 9.3 was silent; gcc 10 did show the warning). The test case is reduced from another case (not shown) that only triggered the warning starting with gcc 11. char * g(); static char c = 0; unsigned int x = 0; void f(char *&p) { if (x > 1) p[1] = 0; p = g(); } void h() { char * p = &c; f(p); } $ g++ -c -O2 -Warray-bounds c.cxx c.cxx: In function ‘void h()’: c.cxx:9:10: warning: array subscript 1 is outside array bounds of ‘char [1]’ [-Warray-bounds] 9 | p[1] = 0; | ~~~~~^~~ c.cxx:3:13: note: while referencing ‘c’ 3 | static char c = 0; | ^ Note: using -O3 silences the warning. $ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/11.1.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-11.1.0/configure --enable-languages=c,c++ --with-system-zlib --enable-lto --with-abi=m64 --disable-multilib Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.1.0 (GCC)