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

            Bug ID: 90105
           Summary: std::forward_list::sort() is not "stable"
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stoyanovmk at ornl dot gov
  Target Milestone: ---

Created attachment 46175
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46175&action=edit
Small example to reproduce the issue

From: https://en.cppreference.com/w/cpp/container/forward_list/sort

"Note: <snip> This function also differs from std::sort in that it does not
require the element type of the forward_list to be swappable, preserves the
values of all iterators, and performs a stable sort."

Output of the attached sample program:
```
List before sort:
a  1
b  2
c  1
d  0

List after sort:
d  0
c  1
a  1
b  2
```
Note that (a, 1) comes before (c, 1), but after the sort the order is reversed.

PS: Example used gcc 7.3.0 under Ubutnu 18.04, but the behavior is pretty
consistent across versions, including 6.3 and 8.0.

Reply via email to