This is the mail archive of the
mailing list for the libstdc++ project.
Re: [patch] std::vector::assign should not call std::vector::swap
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Wed, 1 Oct 2014 13:37:25 +0100
- Subject: Re: [patch] std::vector::assign should not call std::vector::swap
- Authentication-results: sourceware.org; auth=none
- References: <20140925121420 dot GE2669 at redhat dot com>
On 25/09/14 13:14 +0100, Jonathan Wakely wrote:
With C++11 allocator semantics the swap() member might also replace
the allocator, which is only allowed in specific circumstances.
Even though the worst that could happen is we replace the allocator
with an equal one, we should avoid using swap and use the internal
_M_swap_data function instead.
I'm not adding a test, as I don't think this is likely to regress and
to do it properly we'd need to test every member function and ensure
only the correct ones replace the allocator. I searched, and we don't
use swap() inappropriately elsewhere in std::vector.
Tested x86_64-linux, committed to trunk.
... and the 4.9 branch.
* include/bits/vector.tcc (vector::_M_fill_assign): Use _M_swap_data.
diff --git a/libstdc++-v3/include/bits/vector.tcc b/libstdc++-v3/include/bits/vector.tcc
index 5c3dfae..4eacec3 100644
@@ -228,7 +228,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
if (__n > capacity())
vector __tmp(__n, __val, _M_get_Tp_allocator());
else if (__n > size())