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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Here's the fix:

--- a/libstdc++-v3/include/bits/stl_vector.h
+++ b/libstdc++-v3/include/bits/stl_vector.h
@@ -1969,7 +1969,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
        _M_range_initialize_n(_Iterator __first, _Sentinel __last,
                              size_type __n)
        {
-         pointer __start = this->_M_impl._M_start =
+         pointer __start = this->_M_impl._M_start = this->_M_impl._M_finish =
            this->_M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator()));
          this->_M_impl._M_end_of_storage = __start + __n;
          this->_M_impl._M_finish


Because vector(from_range_t, R&&) uses constructor delegation, it means that
the ~vector destructor will be run if an exception happens during the
delegating constructor.

When ~vector runs it destroys all the objects in the range [_M_start,_M_finish)
but we never set _M_finish, so it just destroys garbage.

The fix is to set _M_finish == _M_start so that ~vector has nothing to do.

Reply via email to