I don't know where you got that idea about "need some 'return' value of x--, which is not there". Firstly, it is not exactly clear what you mean. Secondly, regardless of what you mean this doesn't seem to have anything to do with the source of undefined behavior in x = x--
.
x = x--
produces undefined behavior because it attempts to modify x
twice without an intervening sequence point. No "need" for any "return value" is involved here.
The underlying problem with x = x--
is that it has two side-effects that occur at undefined moments in undefined order. One side-effect is introduced by the assignment operator. Another side-effect is introduced by postfix --
operator. Both side-effects attempt to modify the same variable x
and generally contradict each other. This is why the behavior in such cases is declared undefined de jure.
For example, if the original value of x
was 5
, then your expression requires x
to become both 4
(side-effect of decrement) and 5
(side-effect of assignment) at the same time. Needless to say, it is impossible for x
to become 4
and 5
at the same time.
Although such a straightforward contradiction (like 4
vs 5
) is not required for UB to occur. Every time you have two side-effects hitting the same variable without intervening sequence point, the behavior is undefined, even if the values these side-effects are trying to put into the variable match.