This is a stupid question. :)
[EDIT: silly or not, this turned out to be a C ++ complexity issue, see UPDATE_2]
Let's pretend that:
int a = 0;
What happens on line 2 (note that numbers are only markers and do not indicate the exact order):
= [1: write result of (3) to result of (2)] /\ [2: take "b" l-value] [3: convert result of (4) to an r-value ] | [4: take "a" l-value, "increment" and return it]
The “record” in (4) is “ordered” before “reading” in (3), and since there are no sequence points between the points, the side effect is not guaranteed earlier (3) (there is also a “read” inside (4), but it is ordered up to “ records, "so it doesn’t give UB).
So where is the error in the above?
[UPDATE aimed at non-experienced lawyers with consistent points :)]
In other words, the problem is this:
It seems that there is a “competition”, first of all, whether the conversion is l-value-to-r ("read") or increment ("write").
In C, this will give UB, according to JTC1 / SC22 / WG14 N926 "Point Sequence Analysis" * (see, for example, example 5: int x,y; (x=y) + x; // UB ).
Please note that this will not be the case if postincrement will be used, since (3) and (4) will be the same [(3): take "a" value l, convert it to r-value and return that r-value] with a side effect, "write" is delayed until the next point in the sequence appears
_
(*) This looks like the cleanest systematic rationale for a topic posed by members of the C99 Standards Committee.
[UPDATE_2]
Lesson learned: never judge C ++ by the rules of C :)). I did exactly what wondered why the N926 (which purely describes the way things are C99) was "not clear enough" on the subject of preincrements giving l-values.
The question arises: how to build a similar justification for C ++, since it does not exist, because even in the case of C, simply interpreting the standard is rather complicated, and the C ++ language is much more complicated and unclear.
[UPDATE_3]
A discussion of some relevant topics (at least in the ~ new half) in "Uncertainty of the general expression." , plus the issue is discussed by committee members here (see "222. Sequence Points and Lvalue Returning Operators").
c ++ c standards language-lawyer
mlvljr
source share