This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR3609
Jakub Jelinek <jakub@redhat.com> writes:
[...]
| >
| > Note that `"foo" + 10' is *undefined*, but
| > `(char*)((size_t)"foo" + 10)' is *implementation-defined*.
| >
| > I think the resolution everyone wants is that the implementation-defined
| > behavior for string-constant + variable offset is that the result
| > is undefined, even when there are casts involved.
| >
| > I think is not in the spirit of the standard. For example, the C++
| > standard defines implementation-defined behavior as:
| >
| > behavior, for a well-formed program construct and correct data, that
| > depends on the implementation and that each implementation shall docu-
| > ment.
|
| But I think the most natural implementation-defined behaviour for this is
| that it is the same thing as *("foo" + 10), whatever casts you do you're still
| referencing something beyond end of an object.
I disagree. The most natural implementation I see is to do exactly what
the programmer wrote:
1) address -> integer mapping
2) compute the addition
3) integer -> adress mapping
| Anyway, so that we don't spend too much energy on this, following patch
| only optimizes if the string was not casted to non-pointer type before the
| addition, so Franz's testcase works and no gcc testcases need to be changed.
Thanks,
-- Gaby