Reduced from http://stackoverflow.com/q/35002402/2756719, repro: #include <iterator> #include <algorithm> class A { public: A() = default; A(A const & a) = delete; A& operator =(A const & a) = delete; A(A && a) = default; A& operator =(A && a) = default; }; int main() { A a[1], b[1]; std::copy(std::make_move_iterator(a), std::make_move_iterator(a + 1), b); std::move(a, a+1, b); } Compiles on 4.8.2 on Wandbox; fails with 4.9+ with a bogus static assert: In file included from /usr/local/gcc-head/include/c++/6.0.0/bits/char_traits.h:39:0, from /usr/local/gcc-head/include/c++/6.0.0/ios:40, from /usr/local/gcc-head/include/c++/6.0.0/ostream:38, from /usr/local/gcc-head/include/c++/6.0.0/iterator:64, from prog.cc:1: /usr/local/gcc-head/include/c++/6.0.0/bits/stl_algobase.h: In instantiation of 'static _Tp* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _Tp*) [with _Tp = A; bool _IsMove = true]': /usr/local/gcc-head/include/c++/6.0.0/bits/stl_algobase.h:384:44: required from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = true; _II = A*; _OI = A*]' /usr/local/gcc-head/include/c++/6.0.0/bits/stl_algobase.h:420:45: required from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = true; _II = A*; _OI = A*]' /usr/local/gcc-head/include/c++/6.0.0/bits/stl_algobase.h:453:8: required from '_OI std::copy(_II, _II, _OI) [with _II = std::move_iterator<A*>; _OI = A*]' prog.cc:15:76: required from here /usr/local/gcc-head/include/c++/6.0.0/bits/stl_algobase.h:361:4: error: static assertion failed: type is not assignable static_assert( is_copy_assignable<_Tp>::value, ^~~~~~~~~~~~~
It seems that the static_assert should check _IsMove and use either is_copy_assignable<_Tp> or is_move_assignable<_Tp> depending on its value.
Introduced by r204615 for PR 58982
Author: redi Date: Tue Jan 26 19:38:20 2016 New Revision: 232842 URL: https://gcc.gnu.org/viewcvs?rev=232842&root=gcc&view=rev Log: Fix assertions for move assignment of trivial types PR libstdc++/69478 * include/bits/stl_algobase.h (__copy_move<_IsMove, true, random_access_iterator_tag>): Check is_move_assignable when moving. (__copy_move_backwards<_IsMove, true, random_access_iterator_tag>): Likewise. * testsuite/25_algorithms/copy/move_iterators/69478.cc: New. * testsuite/25_algorithms/copy_backward/move_iterators/69478.cc: New. * testsuite/25_algorithms/move/69478.cc: New. * testsuite/25_algorithms/move_backward/69478.cc: new. Added: trunk/libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/69478.cc trunk/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/69478.cc trunk/libstdc++-v3/testsuite/25_algorithms/move/69478.cc trunk/libstdc++-v3/testsuite/25_algorithms/move_backward/69478.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/bits/stl_algobase.h
Fixed on trunk so far.
Author: redi Date: Wed Apr 20 13:00:43 2016 New Revision: 235278 URL: https://gcc.gnu.org/viewcvs?rev=235278&root=gcc&view=rev Log: Fix assertions for move assignment of trivial types Backport from mainline 2016-01-26 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/69478 * include/bits/stl_algobase.h (__copy_move<_IsMove, true, random_access_iterator_tag>): Check is_move_assignable when moving. (__copy_move_backwards<_IsMove, true, random_access_iterator_tag>): Likewise. * testsuite/25_algorithms/copy/move_iterators/69478.cc: New. * testsuite/25_algorithms/copy_backward/move_iterators/69478.cc: New. * testsuite/25_algorithms/move/69478.cc: New. * testsuite/25_algorithms/move_backward/69478.cc: New. Added: branches/gcc-5-branch/libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/69478.cc branches/gcc-5-branch/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/69478.cc branches/gcc-5-branch/libstdc++-v3/testsuite/25_algorithms/move/69478.cc branches/gcc-5-branch/libstdc++-v3/testsuite/25_algorithms/move_backward/69478.cc Modified: branches/gcc-5-branch/libstdc++-v3/ChangeLog branches/gcc-5-branch/libstdc++-v3/include/bits/stl_algobase.h
Author: redi Date: Wed Apr 20 14:30:39 2016 New Revision: 235285 URL: https://gcc.gnu.org/viewcvs?rev=235285&root=gcc&view=rev Log: Fix assertions for move assignment of trivial types Backport from mainline 2016-01-26 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/69478 * include/bits/stl_algobase.h (__copy_move<_IsMove, true, random_access_iterator_tag>): Check is_move_assignable when moving. (__copy_move_backwards<_IsMove, true, random_access_iterator_tag>): Likewise. * testsuite/25_algorithms/copy/move_iterators/69478.cc: New. * testsuite/25_algorithms/copy_backward/move_iterators/69478.cc: New. * testsuite/25_algorithms/move/69478.cc: New. * testsuite/25_algorithms/move_backward/69478.cc: New. Added: branches/gcc-4_9-branch/libstdc++-v3/testsuite/25_algorithms/copy/move_iterators/69478.cc branches/gcc-4_9-branch/libstdc++-v3/testsuite/25_algorithms/copy_backward/move_iterators/69478.cc branches/gcc-4_9-branch/libstdc++-v3/testsuite/25_algorithms/move/69478.cc branches/gcc-4_9-branch/libstdc++-v3/testsuite/25_algorithms/move_backward/69478.cc Modified: branches/gcc-4_9-branch/libstdc++-v3/ChangeLog branches/gcc-4_9-branch/libstdc++-v3/include/bits/stl_algobase.h
Fixed for 4.9.4 and 5.4