This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/47444] False warning: array subscript is above array bounds


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

--- Comment #8 from eidletni at mail dot ru 2011-01-25 18:46:50 UTC ---
(In reply to comment #1)
> >because constructor of struct A never called with "bad"
> How can that be true if the compiler does not know that or could figure that
> out?

In this case I'm expecting nothing.

So, if compiler is smart enough to say 'may be above', why in this simple code
I see no warning:

bool f(unsigned i)
{
    bool v[2] = { 1, 1 };
    return v[i];
}

?

and if we continue, in this code, which EXACTLY have array overflow, I see no
warning:

bool f(unsigned i)
{
    bool v[2] = { 1, 1 };
    return v[i];
}

void g() { f(1000); }

(In reply to comment #1)
>     if ( i>=SIZE && f1() )
>         throw 1;
>     bool v[SIZE] = { 1, 1 };
>     return v[i];
> 
> 
> If f1 returns false, then you have above array bounds access.

I repeat, if I REMOVE this code "if ( i>=SIZE && f1() )", which is equal to f1
function return false, warning message disappears!

(In reply to comment #0)
> 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 }"

I really don't understand, why you guys so easily set wontfix to this bug.
Nobody cares that "inlining constructor" or "return instead throw" depends on
printing warning message?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]