Skip to content

Commit 37f4665

Browse files
committed
[libc++] Make sure that vector copy-construction is disabled for non-copyable types
The Standard requires the value_type of the vector to be Cpp17CopyInsertable in order for copy-construction to be enabled: http://eel.is/c++draft/container.requirements#tab:container.req rdar://problem/56674564 Differential Revision: https://reviews.llvm.org/D74251
1 parent 47f7df8 commit 37f4665

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

libcxx/include/memory

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
16951695
static
16961696
typename enable_if
16971697
<
1698-
is_trivially_move_constructible<_DestTp>::value &&
1698+
is_trivially_copy_constructible<_DestTp>::value &&
16991699
is_same<_RawSourceTp, _RawDestTp>::value &&
17001700
(__is_default_allocator<allocator_type>::value ||
17011701
!__has_construct<allocator_type, _DestTp*, _SourceTp&>::value),
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// Make sure that a std::vector containing move-only types can't be copied.
10+
11+
// UNSUPPORTED: c++98, c++03
12+
// REQUIRES: verify-support
13+
14+
#include <vector>
15+
16+
struct move_only
17+
{
18+
move_only() = default;
19+
move_only(move_only&&) = default;
20+
move_only& operator=(move_only&&) = default;
21+
};
22+
23+
int main(int, char**)
24+
{
25+
std::vector<move_only> v;
26+
std::vector<move_only> copy = v; // expected-error@memory:* {{call to implicitly-deleted copy constructor of 'move_only'}}
27+
return 0;
28+
}

0 commit comments

Comments
 (0)