**Note: The short code in this post reveals the bug, which fails to assign function return value to struct member when executing: a.member = func(b,c); **Note: I tried my best to simplify the source code. I think the source is short and obvious. **Instructions to reveal the bug: Please save the source file to test.cpp and execute the following command lines: g++ test.cpp ./a.out You will see on the screen: 8:-1 8:-1 3:-1 But actually it should be: 8:-1 8:2 3:-1 The reason is that the noted line in the source code: buf[r].son = construct(value, buf[r].son); calls construct, but does not assign the value to buf[r].son. //test.cpp source begins #include <iostream> #include <vector> using namespace std; struct node{ int value; int son; node() {value=0;son=-1;} }; vector<node> buf; int construct(int value, int tree) { int r = buf.size(); buf.push_back(node()); if(tree==-1) { buf[r].value = value; return r; } buf[r] = buf[tree]; // ************* the following line is not executed correctly ******* buf[r].son = construct(value, buf[r].son); return r; } int main(){ construct(8,-1); construct(3,0); for(int i=0;i<buf.size();i++) { cout<<buf[i].value<<":"<<buf[i].son<<endl; } return 0; } //source ends
This is invalid because the next statement is equivent to buf[r].son = construct(value, buf[r].son); buf.operator[](r).son = construct(value, buf.operator[](r).son); So the order of the function call to the operator[] is not defined as you do not have a sequence point inbetween the calls (a comma is not a sequence point).
Reopen to mark as a duplicate of...
...PR 11751. *** This bug has been marked as a duplicate of 11751 ***