Bug 11363

Summary: Execution order is not correct
Product: gcc Reporter: Qing Yang <qyang>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: critical CC: gcc-bugs
Priority: P2    
Version: unknown   
Target Milestone: 3.4.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Qing Yang 2003-06-28 18:15:11 UTC
The details are included in the comments of the following source file:

------------------------------------------------------------------

/*
  File: main.cpp
*/

#include <iostream>
#include <string>
using namespace std;

struct T1 {


  string f()
  {
    cout << "f() called\n";
    return string("1");
  }

  string g()
  {
    cout << "g() called\n";
    return string("2");
  }

};


struct T2 {

  void add(const string& i, const string &j) 
  {
  }
  
};


int main()
{
  T2 t2;
  T1 t1;

  /*
    Consider the following line.
    I expect that t1.f() is called before t1.g(). 
    But the real execution is:
    t1.g() is called before t1.f().

    I compiled this program by:
    
    g++ main.cpp


    Version information:
    g++ (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

  */

  t2.add(t1.f(), t1.g());

  return 0;
}
Comment 1 Andrew Pinski 2003-06-28 18:20:13 UTC
Not a bug. The ISO/ANSI C++ standard (unlike Java) allows the order within sequence points to be 
executed in any order.
Comment 2 Wolfgang Bangerth 2004-08-13 15:39:06 UTC
That's a duplicate of... 
Comment 3 Wolfgang Bangerth 2004-08-13 15:39:31 UTC
...PR 11751. 

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