https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107852
--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> --- With that compiler patch for the missed-optimization one of the two bogus warnings goes away. The second one goes away with this change: --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -374,8 +374,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER pointer _M_allocate(size_t __n) { - typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr; - return __n != 0 ? _Tr::allocate(_M_impl, __n) : pointer(); + pointer __p = pointer(); + if (__n != 0) + { + typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr; + const pointer __s = _M_impl._M_start; + const pointer __f = _M_impl._M_finish; + const pointer __e = _M_impl._M_end_of_storage; + __p = _Tr::allocate(_M_impl, __n); + if (__s != _M_impl._M_start || __f != _M_impl._M_finish + || __e != _M_impl._M_end_of_storage) + __builtin_unreachable(); + } + return __p; } _GLIBCXX20_CONSTEXPR