Bug 15012 - Unexpected behaviour on i--
Summary: Unexpected behaviour on i--
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-19 14:51 UTC by Marcus De Luigi
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus De Luigi 2004-04-19 14:51:36 UTC
Try that code:
---8<---
int j = 2;
int i = 2;
i = i-- + ++j;
cout << i;
--->8---
The suprising result is that i == 1.
I tried this on pc (intel), powerpc and sparc.

The result is because the compiler does something like:
---8<---
tmp1 = i--;
tmp2 = ++j;
i = i + tmp2;
i = tmp1;
--->8---
(check the asm-code for more details).

That's not what the programer expects.
Comment 1 Andrew Pinski 2004-04-19 14:56:15 UTC
Invalid as you are modifing i twice without a sequence point inbetween.
i = i-- + ++j;
^    ^
Comment 2 Wolfgang Bangerth 2004-08-05 14:57:08 UTC
Reopen these bugs... 
Comment 3 Wolfgang Bangerth 2004-08-05 15:01:02 UTC
...mark as duplicate of PR 11751. 

*** This bug has been marked as a duplicate of 11751 ***