https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124216
Bug ID: 124216
Summary: Incorrect warning at high optimizer level
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: afisher at scitec dot com
Target Milestone: ---
Created attachment 63768
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63768&action=edit
The shortest block of code I could find that generates the errant warning
I found this bug while running gcc 13, 14, and 15, with optimizer set to 2 or
3:
In member function 'double (& thing::operator[](int))[2]',
inlined from 'int main()' at <source>:30:21:
<source>:14:23: warning: array subscript [0, 1] is outside array bounds of
'double [2][2]' [-Warray-bounds=]
14 | return stuff[i];
| ~~~~~~~^
<source>: In function 'int main()':
<source>:6:10: note: while referencing 'thing::stuff'
6 | darr stuff[2];
| ^~~~~
I pulled out the smallest amount of code that still generates the error that I
could come up with (attached).
I run it with '-O3 -Wall'