Bug 21246

Summary: Compiler fails when using and incrementing a variable i: f(i,++i) equivalent to f(i+1,i+1); ++i
Product: gcc Reporter: Jesús Andrés <jandres>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: gcc-bugs
Priority: P1 Keywords: wrong-code
Version: 4.0.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Jesús Andrés 2005-04-27 07:36:56 UTC
The next code, should show int the screen "a:2 b:3"; but shows "a:3 b:3".
I have tested it into several versions from 3.3 to 4.0. Always the same result.

void foo(int a,int b)
{
  std::cout<<"a:"<<a<<" b:"<<b<<std::endl;
}

int main()
{
  int n=2;
  foo(n,++n);
}
Comment 1 Giovanni Bajo 2005-04-27 11:40:51 UTC
This is not a bug, the order of evaluation is unspecified.
Read about this here:
http://gcc.gnu.org/bugs.html
section "Increment/decrement operator (++/--) not working as expected"

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