This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/54907] post increasing a value pointed by p in subexpression of an expression modifying p saves the increased value in the wrong place
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 12 Oct 2012 15:40:05 +0000
- Subject: [Bug c/54907] post increasing a value pointed by p in subexpression of an expression modifying p saves the increased value in the wrong place
- Auto-submitted: auto-generated
- References: <bug-54907-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54907
--- Comment #4 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2012-10-12 15:40:05 UTC ---
I believe this code is well-defined.
There are two objects modified, p and *p. p is modified by the
assignment, and C11 6.5.16#3 says "The side effect of updating the stored
value of the left operand is sequenced after the value computations of the
left and right operands.". For postfix increment, which modifies *p, "The
value computation of the result is sequenced before the side effect of
updating the stored value of the operand.". Each object is modified only
once, so there is no issue of two side effects on the same object being
unsequenced. And the value computation of the RHS, using p, is sequenced
before p is updated by the assignment; furthermore, 5.1.2.3#2 says "Value
computation for an lvalue expression includes determining the identity of
the designated object.". So I don't think either case of undefinedness in
6.5#2, "If a side effect on a scalar object is unsequenced relative to
either a different side effect on the same scalar object or a value
computation using the value of the same scalar object, the behavior is
undefined.", applies here.