Bug 69478 - [4.9/5 Regression] std::copy/std::move broken with trivial move-only types
Summary: [4.9/5 Regression] std::copy/std::move broken with trivial move-only types
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 4.9.4
Assignee: Jonathan Wakely
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2016-01-25 22:08 UTC by TC
Modified: 2016-04-20 14:31 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.8.4
Known to fail: 4.9.3, 5.3.0, 6.0
Last reconfirmed: 2016-01-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description TC 2016-01-25 22:08:18 UTC
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,
    ^~~~~~~~~~~~~
Comment 1 TC 2016-01-25 22:17:56 UTC
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.
Comment 2 Jonathan Wakely 2016-01-26 11:18:21 UTC
Introduced by r204615 for PR 58982
Comment 3 Jonathan Wakely 2016-01-26 19:38:52 UTC
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
Comment 4 Jonathan Wakely 2016-01-26 19:39:36 UTC
Fixed on trunk so far.
Comment 5 Jonathan Wakely 2016-04-20 13:01:15 UTC
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
Comment 6 Jonathan Wakely 2016-04-20 14:31:11 UTC
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
Comment 7 Jonathan Wakely 2016-04-20 14:31:29 UTC
Fixed for 4.9.4 and 5.4