This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51731] code generation bug in negative indices in arrays on 64-bit targets
- From: "jakub at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 02 Jan 2012 19:32:08 +0000
- Subject: [Bug c++/51731] code generation bug in negative indices in arrays on 64-bit targets
- Auto-submitted: auto-generated
- References: <bug-51731-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51731
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-01-02 19:32:08 UTC ---
(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."