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; }
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.