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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
A comment added to the code would make the caret diagnostic self-explanatory:

--- a/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
+++ b/libstdc++-v3/include/bits/stl_iterator_base_funcs.h
@@ -149,7 +149,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER
       // concept requirements
       __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
       __glibcxx_assert(__n >= 0);
-      while (__n--)
+      while (__n--) // if n is negative this has undefined behaviour
        ++__i;
     }

That would make the diagnostic look like:

/home/jwakely/gcc/9/include/c++/9.0.1/bits/stl_iterator_base_funcs.h:152:7:
warning: iteration 9223372036854775807 invokes undefined behavior
[-Waggressive-loop-optimizations]
  152 |       while (__n--) // if n is negative this has undefined behaviour
      |     


It's still a bug that there's no "In instantiation of ... required from ...
required from here" context shown though.

Reply via email to