https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123929
Bug ID: 123929
Summary: Regression: Spurious warning in loop iterating over
wrapper with operator int
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: phdiv at fastmail dot fm
Target Milestone: ---
Created attachment 63561
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63561&action=edit
Reproducer
In the attached code, gcc gives a spurious warning during the second array
access in the loop:
> g++ -c -O2 -Warray-bounds arrayfloat.cpp
arrayfloat.cpp: In function 'void f()':
arrayfloat.cpp:29:16: warning: array subscript 99 is above array bounds of
'bool [99]' [-Warray-bounds=]
29 | arrayTags[i] = hasOption(i);
| ~~~~~~~~~~~^
arrayfloat.cpp:19:13: note: while referencing 'arrayTags'
19 | extern bool arrayTags[MAX_NUM];
| ^~~~~~~~~
This warning is new since GCC 12, the previous versions do not issue this.
See also https://godbolt.org/z/a5WsM537j .
I couldn't reduce the test case further; whenever I try to simplify it more,
the warnings goes away.