[Bug c++/51731] code generation bug in negative indices in arrays on 64-bit targets
m.hekkelman at cmbi dot ru.nl
gcc-bugzilla@gcc.gnu.org
Tue Jan 3 07:45:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51731
--- Comment #6 from M.L. Hekkelman <m.hekkelman at cmbi dot ru.nl> 2012-01-03 07:44:55 UTC ---
(In reply to comment #5)
> (In reply to comment #4)
> > Following your logic, if I rewrite the code from:
> >
> > return data.e[-1];
> >
> > to
> >
> > int* ep = data.e;
> > return ep[-1];
> >
> > It would be valid, right? And you still believe the bug report is
> > invalid?
>
> Of course that wouldn't be valid.
> I meant that if you had say array
> type e[10];
> somewhere and
> type *ep = data.e + 9;
> you can then access
> ep[0] + ep[-1] + ep[-9]
> In C++03, please read [expr.add]/5 :
> "If both the pointer operand and the result point to elements of the same array
> object, or one past the last element of the array object, the evaluation shall
> not produce an overflow; otherwise, the behavior is undefined."
I stand corrected.
Still, it would be nice if gcc would then issue a warning instead of only
giving incorrect results when -O3 is specified.
More information about the Gcc-bugs
mailing list