public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "eidletni at mail dot ru" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/47444] New: False warning: array subscript is above array bounds
Date: Mon, 24 Jan 2011 19:20:00 -0000	[thread overview]
Message-ID: <bug-47444-4@http.gcc.gnu.org/bugzilla/> (raw)

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 }"


             reply	other threads:[~2011-01-24 18:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-24 19:20 eidletni at mail dot ru [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-47444-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).