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

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Slightly simpler, with correct assertion now:

--- a/libstdc++-v3/include/bits/vector.tcc
+++ b/libstdc++-v3/include/bits/vector.tcc
@@ -139,6 +139,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
     {
       const size_type __n = __position - begin();
       if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
+       {
+         __glibcxx_assert(__position != const_iterator());
+         if (__position == const_iterator())
+           __builtin_unreachable(); // PR 106434
+
          if (__position == end())
            {
              _GLIBCXX_ASAN_ANNOTATE_GROW(1);
@@ -159,6 +164,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
              _M_insert_aux(__position, __x);
 #endif
            }
+       }
       else
 #if __cplusplus >= 201103L
        _M_realloc_insert(begin() + (__position - cbegin()), __x);


The __builtin_unreachable would be unnecessary if __glibcxx_assert expanded to
that when assertions are disabled (so the macro expands to either an assertion,
or a hint that the condition is always true). I think I tried that and it
caused problems though.

Reply via email to