https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87742
Bug ID: 87742
Summary: False warning 'array
Product: gcc
Version: 6.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: lh_mouse at 126 dot com
Target Milestone: ---
Created attachment 44894
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44894&action=edit
reduced testcase using CReduce
Compiling the attached source file with `-O2 -Wall` results in a warning about
array subscript out of bound:
```
lh_mouse@lhmouse-ideapad ~/Desktop $ g++-7 test.cpp -O2 -Wall -c -o /dev/null
test.cpp: In member function ‘void H::w() const’:
test.cpp:35:45: warning: array subscript is above array bounds [-Warray-bounds]
const type_info &m_fn3() const { return *b[o]; }
~^
lh_mouse@lhmouse-ideapad ~/Desktop $ g++-8 test.cpp -O2 -Wall -c -o /dev/null
test.cpp:25:32: warning: unnecessary parentheses in declaration of ‘b’
[-Wparentheses]
static const type_info *const(b[]);
^
test.cpp:48:48: warning: unnecessary parentheses in declaration of ‘b’
[-Wparentheses]
template <typename... l> const type_info *const(F<l...>::b[]){&typeid(l)...};
^
test.cpp: In member function ‘void H::w() const’:
test.cpp:35:45: warning: array subscript 3 is above array bounds of ‘const
std::type_info* const [3]’ [-Warray-bounds]
const type_info &m_fn3() const { return *b[o]; }
~^
```
(<https://wandbox.org/permlink/tv83ODDn9mWNhjvZ> for an online version.)
but in the context where `o` is used, it is expected to have a value of 2
instead of 3, so the out-of-bound access shouldn't happen.
Original (unreduced) code is at
<https://github.com/lhmouse/asteria/blob/c44081129943334baee36287378a0227edba9fd7/asteria/src/value.cpp#L292>.
The out-of-bound access is reported at
<https://github.com/lhmouse/asteria/blob/c44081129943334baee36287378a0227edba9fd7/asteria/src/rocket/variant.hpp#L330>.