PR libstdc++/92124 fix incorrect container move assignment
authorJonathan Wakely <jwakely@redhat.com>
Thu, 17 Oct 2019 14:21:27 +0000 (15:21 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 17 Oct 2019 14:21:27 +0000 (15:21 +0100)
commit47519a5687d48af4b932d54b0525fafcdc0e48d6
tree3613ae6f84da1b3ebd3fbbf1e137b4286ffb4dc1
parent58baf7ab85cbb1068a651c96f7d56e2902ead6cc
PR libstdc++/92124 fix incorrect container move assignment

The container requirements say that for move assignment "All existing
elements of [the target] are either move assigned or destroyed". Some of
our containers currently use __make_move_if_noexcept which makes the
move depend on whether the element type is nothrow move constructible.
This is incorrect, because the standard says we must move assign, not
move or copy depending on the move constructor.

Use make_move_iterator instead so that we move unconditionally. This
ensures existing elements won't be copy assigned.

PR libstdc++/92124
* include/bits/forward_list.h
(_M_move_assign(forward_list&&, false_type)): Do not use
__make_move_if_noexcept, instead move unconditionally.
* include/bits/stl_deque.h (_M_move_assign2(deque&&, false_type)):
Likewise.
* include/bits/stl_list.h (_M_move_assign(list&&, false_type)):
Likewise.
* include/bits/stl_vector.h (_M_move_assign(vector&&, false_type)):
Likewise.
* testsuite/23_containers/vector/92124.cc: New test.

From-SVN: r277113
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/forward_list.h
libstdc++-v3/include/bits/stl_deque.h
libstdc++-v3/include/bits/stl_list.h
libstdc++-v3/include/bits/stl_vector.h
libstdc++-v3/testsuite/23_containers/deque/92124.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/forward_list/92124.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/list/92124.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/vector/92124.cc [new file with mode: 0644]