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

           Summary: False warning: array subscript is above array bounds
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: eidle...@mail.ru


Created attachment 23104
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23104
c++ code

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/home/eid-letni/opt/gcc/libexec/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/home/eid-letni/opt/gcc
--enable-languages=c,c++ : (reconfigured) ../configure
--prefix=/home/eid-letni/opt/gcc --enable-languages=c,c++,lto --no-create
--no-recursion
Thread model: posix
gcc version 4.6.0 20110124 (experimental) (GCC) 

$ uname -a
Linux eidletni 2.6.35-24-generic #42-Ubuntu SMP Thu Dec 2 01:41:57 UTC 2010
i686 GNU/Linux

$ g++ -O3 -Wall -c a.ii

Warning in function "bool f2(unsigned)" :

bool f1();

struct A
{
    bool b1;
    bool b2;
    A(unsigned i);
};

bool f2(unsigned i)
{
    enum { SIZE = 2 };
    if ( i>=SIZE && f1() )
        throw 1;
    bool v[SIZE] = { 1, 1 };
    return v[i];
}

A::A(unsigned i):
    b1(f2(i)),
    b2(f2(i))
{}

This warning is false, because constructor of struct A never called with "bad"
parameters.

Warning disappears if:
*) remove f1() call in "if ( i>=SIZE && f1() )"
*) make "return true" instead of "throw 1"
*) inline struct A constructor, "inline A::A(unsigned i)"
*) make size of array "bool v[]" equal 1, "enum { SIZE = 1 }"

Reply via email to