[libcxx-commits] [libcxx] r371067 - [libc++] Add a test for resizing of a vector with copy-only elements

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 5 06:50:18 PDT 2019


Author: ldionne
Date: Thu Sep  5 06:50:18 2019
New Revision: 371067

URL: http://llvm.org/viewvc/llvm-project?rev=371067&view=rev
Log:
[libc++] Add a test for resizing of a vector with copy-only elements

See https://reviews.llvm.org/D62228#1658620

Added:
    libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/resize.copy_only.pass.sh.cpp

Added: libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/resize.copy_only.pass.sh.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/resize.copy_only.pass.sh.cpp?rev=371067&view=auto
==============================================================================
--- libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/resize.copy_only.pass.sh.cpp (added)
+++ libcxx/trunk/test/std/containers/sequences/vector/vector.modifiers/resize.copy_only.pass.sh.cpp Thu Sep  5 06:50:18 2019
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// RUN: %build -fno-exceptions
+// RUN: %run
+
+// RUN: %build
+// RUN: %run
+
+// UNSUPPORTED: c++98, c++03
+
+// <vector>
+
+// Test that vector won't try to call the move constructor when resizing if
+// the class has a deleted move constructor (but a working copy constructor).
+
+#include <vector>
+
+class CopyOnly {
+public:
+  CopyOnly() { }
+
+  CopyOnly(CopyOnly&&) = delete;
+  CopyOnly& operator=(CopyOnly&&) = delete;
+
+  CopyOnly(const CopyOnly&) = default;
+  CopyOnly& operator=(const CopyOnly&) = default;
+};
+
+int main() {
+    std::vector<CopyOnly> x;
+    x.emplace_back();
+
+    CopyOnly c;
+    x.push_back(c);
+
+    return 0;
+}




More information about the libcxx-commits mailing list