[Bug middle-end/45978] New: bogus "array subscript is above array bounds" warning in extremely simple code with no loops

miles at gnu dot org gcc-bugzilla@gcc.gnu.org
Tue Oct 12 07:37:00 GMT 2010


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45978

           Summary: bogus "array subscript is above array bounds" warning
                    in extremely simple code with no loops
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: miles@gnu.org


Created attachment 22021
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22021
C++ source file illustrating bug

[I don't know if the "component:" field is correct, but there doesn't seem to
be a "I don't know" option]

There are many bugs in gcc's bugzilla related to bogus array-bounds warnings,
but most of them seem to involve loops and other situations that may need
non-trivial analysis by the compiler.

However the attached C++ source file ("tt.cc") seems to be almost trivial; it
contains no loops at all, and all array references use a constant (and valid)
index, but it nonetheless elicits an "array subscript is above array bounds"
warning from the compiler.  As far as I can figure, the warning is bogus.

Compilation looks like:

   $ g++-snapshot -O3 -S -Wall -Wextra tt.cc
   tt.cc: In function 'Z test()':
   tt.cc:15:21: warning: array subscript is above array bounds [-Warray-bounds]

Version info:

   $ g++-snapshot --version
   g++ (Debian 20101009-1) 4.6.0 20101009 (experimental) [trunk revision
165234]
   Copyright (C) 2010 Free Software Foundation, Inc.
   This is free software; see the source for copying conditions.  There is NO
   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

"g++-snapshot" just invokes g++ from Debian's gcc-snapshot package, which is a
somewhat recent trunk snapshot.

["tt.cc" is as minimal as I can get it -- moving, eliminating, or changing any
field in any of the structures seems to silence the warning.]

Thanks,

-Miles



More information about the Gcc-bugs mailing list