This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] PR libstdc++/83982 fix exception-safety guarantee of std::vector::resize
- From: Daniel Trebbien <dtrebbien at gmail dot com>
- To: Jonathan Wakely <jwakely at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Thu, 14 Jun 2018 05:01:46 +0000
- Subject: Re: [PATCH] PR libstdc++/83982 fix exception-safety guarantee of std::vector::resize
- References: <20180613234328.GA27409@redhat.com>
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