https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121890
Bug ID: 121890 Summary: Several algorithms do not use iterator's difference_type for arithmetic Product: gcc Version: 16.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- #include <algorithm> #include <testsuite_iterators.h> namespace __gnu_test { // Ensure that the iterator's difference_type is always used. template<typename T, typename D> void operator+(random_access_iterator_wrapper<T>, D) = delete; template<typename T, typename D> void operator+(D, random_access_iterator_wrapper<T>) = delete; } void test() { int a[1]; __gnu_test::random_access_container<int> c(a); std::fill_n(c.begin(), 1U, 0); std::push_heap(c.begin(), c.end()); std::for_each_n(c.begin(), 1U, [](int){}); std::nth_element(c.begin(), c.begin(), c.end()); } We get several errors like this: /usr/include/c++/15/bits/stl_algo.h:3826:33: error: use of deleted function ‘void __gnu_test::operator+(random_access_iterator_wrapper<T>, D) [with T = int; D = unsigned int]’ 3826 | auto __last = __first + __n2; | ~~~~~~~~^~~~~~