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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2025-10-09

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
We could make the erroneous std::prev call a no-op though:

-- a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
+++ b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
@@ -201,7 +201,7 @@ namespace __detail
       // concept requirements
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_assert(__n >= 0);
-      while (__n--)
+      while (__n-- > 0)
        ++__i;
     }


I was going to do that only if n was an integral type, because otherwise we
don't know if the > operator works or not (which
https://cplusplus.github.io/LWG/issue3439 needs to fix) but we already do __n
>= 0 for the assertion.

So let's make this change. If the assertion is not enabled then it's better to
do nothing than to have undefined behaviour.

Reply via email to