[libcxx-commits] [PATCH] D74251: [libc++] Make sure that vector copy-construction is disabled for non-copyable types

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Feb 7 12:35:51 PST 2020


ldionne created this revision.
ldionne added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, dexonsmith, jkorous, christof.
Herald added a project: libc++.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74251

Files:
  libcxx/include/memory
  libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.fail.cpp


Index: libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.fail.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/containers/sequences/vector/vector.cons/copy.move_only.fail.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Make sure that a std::vector containing move-only types can't be copied.
+
+// UNSUPPORTED: c++98, c++03
+// REQUIRES: verify-support
+
+#include <vector>
+
+struct move_only
+{
+    move_only() = default;
+    move_only(move_only&&) = default;
+    move_only& operator=(move_only&&) = default;
+};
+
+int main(int, char**)
+{
+    std::vector<move_only> v;
+    std::vector<move_only> copy = v; // expected-error at memory:* {{call to implicitly-deleted copy constructor of 'move_only'}}
+    return 0;
+}
Index: libcxx/include/memory
===================================================================
--- libcxx/include/memory
+++ libcxx/include/memory
@@ -1695,7 +1695,7 @@
         static
         typename enable_if
         <
-            is_trivially_move_constructible<_DestTp>::value &&
+            is_trivially_copy_constructible<_DestTp>::value &&
             is_same<_RawSourceTp, _RawDestTp>::value &&
             (__is_default_allocator<allocator_type>::value ||
              !__has_construct<allocator_type, _DestTp*, _SourceTp&>::value),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74251.243267.patch
Type: text/x-patch
Size: 1708 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200207/ad2b696e/attachment.bin>


More information about the libcxx-commits mailing list