public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/47444] New: False warning: array subscript is above array bounds
@ 2011-01-24 19:20 eidletni at mail dot ru
  2011-01-24 21:32 ` [Bug c++/47444] " pinskia at gcc dot gnu.org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: eidletni at mail dot ru @ 2011-01-24 19:20 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: eidletni@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 }"


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2012-10-31 19:25 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-24 19:20 [Bug c++/47444] New: False warning: array subscript is above array bounds eidletni at mail dot ru
2011-01-24 21:32 ` [Bug c++/47444] " pinskia at gcc dot gnu.org
2011-01-24 22:48 ` paolo.carlini at oracle dot com
2011-01-24 23:01 ` manu at gcc dot gnu.org
2011-01-25 11:09 ` rguenth at gcc dot gnu.org
2011-01-25 13:17 ` manu at gcc dot gnu.org
2011-01-25 13:20 ` redi at gcc dot gnu.org
2011-01-25 13:25 ` manu at gcc dot gnu.org
2011-01-25 19:10 ` eidletni at mail dot ru
2011-01-25 19:46 ` redi at gcc dot gnu.org
2011-01-25 19:53 ` eidletni at mail dot ru
2011-03-26 16:06 ` aj664 at hotmail dot com
2011-03-26 17:49 ` aj664 at hotmail dot com
2011-03-26 18:41 ` manu at gcc dot gnu.org
2012-10-31 19:25 ` eidletni at mail dot ru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).