https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120954
Bug ID: 120954 Summary: [15 Regression] False positive -Warray-bounds=2 warning Product: gcc Version: 15.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sirl at gcc dot gnu.org Target Milestone: --- This small code snippet warns with r15-9921 (r15-9866 was still OK): static const int map01[32] = { 11, 12, 13, 14, 15 }; static const int map02[32] = { 21, 22, 23, 24, 25 }; static const int map03[32] = { 31, 32, 33, 34, 35 }; static const int map11[32] = { 111, 112, 113, 114, 115 }; static const int map12[32] = { 121, 122, 123, 124, 125 }; static const int map13[32] = { 131, 132, 133, 134, 135 }; int test(int n, int ver) { int r = 0; if (n >= 0 && n < 32) { r = ((ver >= 4) ? ((ver >= 0x65) ? map01 : map02 ) : map03)[n]; } else if (n >= 0x100 && n < 0x120) { r = ((ver >= 4) ? ((ver >= 0x65) ? map11 : map12 ) : map13)[n - 0x100]; }; return r; } # g++-15 -c -O2 -Warray-bounds=2 test-Warray-bounds.cpp test-Warray-bounds.cpp: In function 'int test(int, int)': test-Warray-bounds.cpp:16:86: warning: intermediate array offset -256 is outside array bounds of 'const int [32]' [-Warray-bounds=] 16 | r = ((ver >= 4) ? ((ver >= 0x65) ? map11 : map12 ) : map13)[n - 0x100]; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ This one also might have been caused by commit r15-9896-g7fdf47538a659f6af8dadbecbb63c8a226b63754 Author: Jakub Jelinek <ja...@redhat.com> Date: Tue Jul 1 15:28:10 2025 +0200 c++: Fix up cp_build_array_ref COND_EXPR handling [PR120471] But this time I'm not very confident about that. Compiling this a C code doesn't warn.