http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60957
Bug ID: 60957
Summary: [4.9/4.10 Regression] Bogus error: array subscript is
above array bounds [-Werror=array-bounds]
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hjl.tools at gmail dot com
[hjl@gnu-6 gcc]$ cat bar.cc
class XXX
{
private:
bool _enabled;
public:
bool on() const {return _enabled;}
};
extern XXX xxx;
extern bool foobar(const unsigned int);
extern void foo (const char *);
extern const unsigned int bar (void * p);
extern void bar2(void * ptr)
{
static const unsigned int size_map[] = { 0, 1, 2, 0, 4, 0, 0, 0, 8};
const unsigned int old_width = bar (ptr);
if(!(old_width <= 8))
if(xxx.on())
foo ("");
unsigned int size = size_map[old_width];
if(!(size != 0))
if(xxx.on())
foo ("");
if(!(foobar(size)))
foo ("");
}
[hjl@gnu-6 gcc]$ ./xgcc -B./ -S -O2 -Wall bar.cc -Werror
bar.cc: In function \u2018void bar2(void*)\u2019:
bar.cc:19:41: error: array subscript is above array bounds
[-Werror=array-bounds]
unsigned int size = size_map[old_width];
^
cc1plus: all warnings being treated as errors
[hjl@gnu-6 gcc]$