// { dg-do run { target c++11 } } #include #include #include // PR libstdc++/66742 // abort on sorting list with custom allocator that is not stateless template> bool is_sorted(const List& l, Cmp cmp = {}) { auto it = l.begin(); auto next = it; const auto end = l.end(); if (it == end) return true; while (++next != end) if (cmp(*next, *it)) return false; else it = next; return true; } void test01() { using Alloc = __gnu_test::uneq_allocator; Alloc a1(1); std::list l(a1); for (int i = 0; i < 1000; ++i) { l.push_front(i); l.push_back(i + (i % 3)); } const auto orig = l; l.sort(); VERIFY( is_sorted(l) ); l.sort(); VERIFY( is_sorted(l) ); l = orig; l.sort(std::less()); VERIFY( is_sorted(l) ); l.sort(std::greater()); VERIFY( is_sorted(l, std::greater()) ); } void test02() { // The standard doesn't require comparisons to be const-correct. // The initial fix for PR 66742 caused a regression here. struct X { bool operator<(X&) /* non-const */ { return false; } }; struct Cmp { bool operator()(X&, X&) /* non-const */ { return false; } }; std::list l; l.sort(); Cmp c; l.sort(c); } int main() { test01(); test02(); }