[Bug c++/91774] Assignment from return value of function to reference returned by function occasionally produces wrong results
smartman1996 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Sep 16 09:10:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91774
--- Comment #3 from 이경룡 <smartman1996 at gmail dot com> ---
Oops. Sorry for the unclear explanation on the core. Forgive me.
the throw statement is not the bug itself but acted as a detector for the bug
line 28868 ~ 28925: Definition of Interpreter::Read()
line 28901 has statement:
ListManager[probe].rchild = ListManager.Alloc();
which corresponds to the statement in the prior explanation:
a[index].x = b.CalcFunc();
line 28557 ~ 28587: Definition of ListPocket::Alloc();
{
while(true){
//something
}
//some calculation
return allocIndex;
}
Observing the bug with the testcase:
among many times the ListPocket::Alloc() is invoked via
"ListManager.Alloc()"
when the if statement with a for loop inside is triggered, the return value
is expected to be 30
(sorry for mistaking it as a while loop in the prior
explanation)
the problem is that
the return value of "ListManager.Alloc()" is not properly assigned into the
reference "ListManager[probe].rchild"
In fact, the gdb shows that the return value is 30(even immediately after
the return)
and using std::cout to print out the value reports as 30 inside and outside
the function prints 30.
the cout part was disabled by the preprocessor and cannot be seen.
i.e. ListManager[probe].rchild remains 29 (it was formerly 29)
the equivalent statement that works well is:
{
auto temp = ListManager.Alloc();
ListManager[probe].rchild = temp;
}
Note: sorry for the source reduction being late.
More information about the Gcc-bugs
mailing list