[PATCH] libstdc++/77334 move assign RB trees of non-copyable types

Jonathan Wakely jwakely@redhat.com
Wed Aug 31 16:58:00 GMT 2016

On 30/08/16 11:17 +0100, Jonathan Wakely wrote:
>On 27/08/16 21:29 +0200, François Dumont wrote:
>>On 23/08/2016 15:17, Jonathan Wakely wrote:
>>>This fixes move assignment of RB trees to tag dispatch so the branch
>>>that copies nodes doesn't need to be well-formed.
>>>   PR libstdc++/77334
>>>   * include/bits/stl_tree.h (_Rb_tree::_M_move_assign): New functions.
>>>   (_Rb_tree::operator=(_Rb_tree&&)): Dispatch to _M_move_assign.
>>>   * testsuite/23_containers/map/77334.cc: New test.
>>>Tested powerpc64le-linux, committed to trunk.
>>>Backports to 5 and 6 to follow.
>>+    operator=(_Rb_tree&& __x)
>>+    noexcept(_Alloc_traits::_S_nothrow_move()
>>+	     && is_nothrow_move_assignable<_Compare>::value)
>>+    {
>>+      _M_impl._M_key_compare = __x._M_impl._M_key_compare;
>>Shouldn't it be:
>>+      _M_impl._M_key_compare = std::move(__x._M_impl._M_key_compare);
>>I can't find anything in Standard saying to do so but wouldn't it be more natural ?
>Yes, I can't think of any reason that would cause a problem. The
>moved-from container is empty after the move assignment so even if
>moving the comparison object changes the order it defines, no elements
>will be left in an invalid order.
>We don't need to use the comparison object after it's moved, but I'll
>add a test to guarantee that remains true.

Done with this patch.

Tested powerpc64le-linux, committed to trunk.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 2804 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160831/7df57e8c/attachment.bin>

More information about the Gcc-patches mailing list