This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR libstdc++/83982 fix exception-safety guarantee of std::vector::resize


On Wed, Jun 13, 2018 at 11:43 PM, Jonathan Wakely <jwakely@redhat.com>
wrote:

> Construct new elements before moving existing ones, so that if a default
> constructor throws, the existing elements are not left in a moved-from
> state.
>
> 2018-06-14  Daniel Trebbien <dtrebbien@gmail.com>
>             Jonathan Wakely  <jwakely@redhat.com>
>
>         PR libstdc++/83982
>         * include/bits/vector.tcc (vector::_M_default_append(size_type)):
>         Default-construct new elements before moving existing ones.
>         * testsuite/23_containers/vector/capacity/resize/strong_guaran
> tee.cc:
>         New.
>
> Tested powerpc64le-linux.
>
> Daniel (CC'd) originally proposed a fix based on the code used in
> vector::_M_realloc_insert. This is a slightly simpler fix, possible
> because resize only inserts at the end not in the middle. I also wrote
> a new testcase which is also valid in C++98, where the lack of move
> constructors means the strong exception-safety guarantee is always
> met. (Which means the bug is a regression since the default mode
> changed to -std=gnu++14 in GCC 6.1).
>
> I plan to commit this to trunk tomorrow, and backport soon too.
>
>

Thank you, Jonathan.  Your simpler patch looks good to me.  I have also
verified that the strong_guarantee.cc test case fails with g++-8 (Homebrew
GCC 8.1.0) macOS AMD64 architecture, and passes when the changes to
vector.tcc are applied to /usr/local/include/c++/8.1.0/bits/vector.tcc.

Daniel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]