Edit to clarify: I am not asking about how sequencing works. This question is not a duplicate of the question that it was marked as duplicate of. I already understand that x++ * ++x
is UB. I am asking about the meaning of the phrase "The order of evaluation of expressions is left to right".
This line is taken from Bjarne Stroustrup's "A Tour of C++", 2nd edition.
I would have expected this to mean that snippets like int x=2;int y=x++ * ++x
are well-defined. Evaluating left-to-right means, in my understanding, that x++
is evaluated first (value 2), ++x
is evaluated second (value 4), and the final value of y
is 8
.
But clang warns about multiple unsequenced modifications to 'x'
, so I think my understanding of what Stroustrup's quote means must be wrong.
Can anyone explain what he actually means?