Bug 77493

Summary: cout output is out of order
Product: [Retired] Red Hat Linux Reporter: Paisa Seeluangsawat <paisa>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-11-07 22:42:28 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Paisa Seeluangsawat 2002-11-07 22:42:22 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830

Description of problem:
With default installation of Redhat 8.0  "gcc version 3.2 20020903 (Red Hat
Linux 8.0 3.2-7)", the code attached prints "21" in stead of "12"


Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. g++ a.cc
2. ./a.out


Actual Results:  "21"

Expected Results:  "12"

Additional info:

// ---- a.cc -----------------

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
  vector<int> v(5);
  for (int i=0; i<5; i++)  v[i]=i;
  vector<int>::iterator i= find(v.begin(), v.end(), 1);
  cout << (*i++) << (*i++) << endl;  
  // should print "12", but I got "21"
  return 0;
}

Comment 1 Jakub Jelinek 2002-11-07 23:16:28 UTC
No, it is correct. When calling ostream::operator<<(int) there is no sequence
point between evaluation of ostream (together with the other operator<<(int))
and i++. Use at most one ++ or -- between each two sequence points to avoid this.