libstdc++: Use allocator to construct std::stacktrace_entry objects
authorJonathan Wakely <jwakely@redhat.com>
Tue, 12 Apr 2022 15:48:31 +0000 (16:48 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 12 Apr 2022 21:38:31 +0000 (22:38 +0100)
commit7cf88759957a7006e1e1d0a82a1a4de3c4db109e
treeb29b455818f1ac45dfd8f354e3f53d49e64db0b1
parente48933f00d676658ad065d9691a1b61446745386
libstdc++: Use allocator to construct std::stacktrace_entry objects

Because std::basic_stacktrace<A> is an allocator-aware container its
elements should be initialized using allocator_traits<A>::construct and
destroyed using allocator_traits<A>::destroy.

This adds new _M_clone and _M_assign helper functions to construct
elements correctly and uses those functions instead of calling
std::uninitialized_copy_n.

The _Impl::_M_destroy function needs to be passed an allocator to
destroy the elements correctly, so is replaced by _M_resize which can
also be used to trim the container to a smaller size.

Because destroying and creating std::stacktrace_entry objects is cheap,
the copy/move assignment operators can just destroy all existing
elements and use _Impl._M_clone or _Impl._M_assign to create new ones.

libstdc++-v3/ChangeLog:

* include/std/stacktrace (basic_stacktrace): Use _Impl::_M_clone
or _Impl::_M_assign to initialize elements in allocated storage.
(basic_stacktrace::_M_clear()): Use _Impl::_M_resize instead of
_Impl::_M_destroy.
(basic_stacktrace::_Impl::_M_destroy()): Replace with ...
(basic_stacktrace::_Impl::_M_resize(size_type, allocator&)): New
function.
(basic_stacktrace::_Impl::_M_push_back): Use _M_xclone. Construct
new element using allocator.
(basic_stacktrace::_Impl::_M_clone): New function.
(basic_stacktrace::_Impl::_M_xclone): New function.
(basic_stacktrace::_Impl::_M_assign): New function.
libstdc++-v3/include/std/stacktrace