Create and compile a simple program:
i = 6+ i++ + 2000;
std::cout << i << std::endl;
when running, it results "1" even when it should result "2006". If I remove the
postfix operation "i++" the result is correct("2006"). As long as I keep
that "i++" inside the equation I can divide, multiply, substract or add what
ever I like, and the result is allways "1". ( There is exeption: Dividing with
zero, creates warning and the result program craches like it should do. )
example: If the equation is
i = (6+ i++ + 2000)/2;
then "i" is still the same 1.
If I replace the postfix "i++" with prefix "++i" then the equation is
calculated correctly, but the meaning is different( as you know prefix and
postfix adding have different behaviour)).
You are modifying i twice without an intervening sequence point, which is
invalid. See the documentation on -Wsequence-point.
Reopen these bugs...
...mark as duplicate of PR 11751.
*** This bug has been marked as a duplicate of 11751 ***