https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83239
--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> --- This libstdc++ patch helps avoid both the warning and the bogus memset. if Jonathan isn't opposed to this kind of annotation I think there might be other places in vector where this approach could improve the emitted object code. diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc index eadce3c..8093f5e 100644 --- a/libstdc++-v3/include/bits/vector.tcc +++ b/libstdc++-v3/include/bits/vector.tcc @@ -582,8 +582,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { if (__n != 0) { - if (size_type(this->_M_impl._M_end_of_storage - - this->_M_impl._M_finish) >= __n) + size_type __navail = size_type(this->_M_impl._M_end_of_storage + - this->_M_impl._M_finish); + + if (__navail > max_size () - size ()) + __builtin_unreachable (); + + if (__navail >= __n) { _GLIBCXX_ASAN_ANNOTATE_GROW(__n); this->_M_impl._M_finish =