[Bug libstdc++/90105] std::forward_list::sort() is not "stable"
stoyanovmk at ornl dot gov
gcc-bugzilla@gcc.gnu.org
Tue Apr 16 19:24:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90105
--- Comment #2 from stoyanovmk at ornl dot gov ---
Tested the fix provided by Jonathan Wakely, I can confirm the fix.
Ran several tests with the included small example and the code where I found
the issue in the first place.(In reply to Jonathan Wakely from comment #1)
> I think this is the fix:
>
> --- a/libstdc++-v3/include/bits/forward_list.tcc
> +++ b/libstdc++-v3/include/bits/forward_list.tcc
> @@ -469,9 +469,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
> __p = static_cast<_Node*>(__p->_M_next);
> --__psize;
> }
> - else if (__comp(*__p->_M_valptr(), *__q->_M_valptr()))
> + else if (!__comp(*__q->_M_valptr(), *__p->_M_valptr()))
> {
> - // First node of p is lower; e must come from p.
> + // First node of q is not lower; e must come from p.
> __e = __p;
> __p = static_cast<_Node*>(__p->_M_next);
> --__psize;
Tested the fix, I can confirm it works.
Ran several tests with the included small example and the code where I found
the issue in the first place.
More information about the Gcc-bugs
mailing list