I know that C and C++ and different languages, but the following applies to both.
TL/DR
I know that i = i++; is UB, because i is modified twice in the expression and C and C++ forbids it.
References :
C99 6.5 :
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. If there are multiple allowable orderings of the subexpressions of an expression, the behavior is undefined if such an unsequenced side effect occurs in any of the orderings
C++ 11 - 1.9 15 :
If a side effect on a scalar object is unsequenced relative to either another side effect on the same scalar object or a value computation using the value of the same scalar object, and they are not potentially concurrent, the behavior is undefined.
So I understand that *i = *i++ + *j++; causes UB, because post incrementation on i and affectation to *i may be unsequenced, and CLang issues a warning in C or C++ mode : warning: unsequenced modification and access to 'i' [-Wunsequenced] *i = *i++ + *j++;
But I do not understand the same warning on *i++ = *i + *j++;. Because here, we first compute the right part, affect it, and increment after the affectation.
And specs for both language say (same paragraph, just above) :
The value computations of the operands of an operator are sequenced before the value computation of the result of the operator
END TL/DR
So the question is :
Is this line
*i++ = *i + *j++;
undefined behaviour, or is Clang (version 3.4.1) too conservative in issuing a warning on it ?
=) is not a sequence point. - EOF*i + *j++must be evaluated before=is evaluated, but that doesn't dictate when (on the left)*i++is evaluated. - Drew Dormann