[Bug libstdc++/90105] std::forward_list::sort() is not "stable"

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Apr 16 19:06:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90105

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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;


More information about the Gcc-bugs mailing list