summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/containers
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2019-09-13 16:09:33 +0000
committerEric Fiselier <eric@efcs.ca>2019-09-13 16:09:33 +0000
commit2a573784f3679a7abab921018eb1c585dce8e669 (patch)
treec68c186474a5b4906b4601c57ab45ce8c06ecd3b /libcxx/test/std/containers
parent69ba3defafa7afc2ddcc0dc0d541334e0220cbb5 (diff)
downloadbcm5719-llvm-2a573784f3679a7abab921018eb1c585dce8e669.tar.gz
bcm5719-llvm-2a573784f3679a7abab921018eb1c585dce8e669.zip
Recommit r370502: Make `vector` unconditionally move elements when
exceptions are disabled. The patch was reverted due to some confusion about non-movable types. ie types that explicitly delete their move constructors. However, such types do not meet the requirement for `MoveConstructible`, which is required by `std::vector`: Summary: `std::vector<T>` is free choose between using copy or move operations when it needs to resize. The standard only candidates that the correct exception safety guarantees are provided. When exceptions are disabled these guarantees are trivially satisfied. Meaning vector is free to optimize it's implementation by moving instead of copying. This patch makes `std::vector` unconditionally move elements when exceptions are disabled. This optimization is conforming according to the current standard wording. There are concerns that moving in `-fno-noexceptions`mode will be a surprise to users. For example, a user may be surprised to find their code is slower with exceptions enabled than it is disabled. I'm sympathetic to this surprised, but I don't think it should block this optimization. Reviewers: mclow.lists, ldionne, rsmith Reviewed By: ldionne Subscribers: zoecarver, christof, dexonsmith, libcxx-commits Tags: #libc Differential Revision: https://reviews.llvm.org/D62228 llvm-svn: 371867
Diffstat (limited to 'libcxx/test/std/containers')
-rw-r--r--libcxx/test/std/containers/sequences/vector/vector.modifiers/resize.copy_only.pass.sh.cpp45
-rw-r--r--libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.fail.cpp45
2 files changed, 45 insertions, 45 deletions
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/resize.copy_only.pass.sh.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/resize.copy_only.pass.sh.cpp
deleted file mode 100644
index b24736e22b6..00000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/resize.copy_only.pass.sh.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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;
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.fail.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.fail.cpp
new file mode 100644
index 00000000000..2b4a5a9e2cd
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/resize_not_move_insertable.fail.cpp
@@ -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
+
+
+// <vector>
+
+// Test that vector produces a decent diagnostic for user types that explicitly
+// delete their move constructor. Such types don't meet the Cpp17CopyInsertible
+// requirements.
+
+#include <vector>
+
+template <int>
+class BadUserNoCookie {
+public:
+ BadUserNoCookie() { }
+
+ BadUserNoCookie(BadUserNoCookie&&) = delete;
+ BadUserNoCookie& operator=(BadUserNoCookie&&) = delete;
+
+ BadUserNoCookie(const BadUserNoCookie&) = default;
+ BadUserNoCookie& operator=(const BadUserNoCookie&) = default;
+};
+
+int main() {
+ // expected-error@memory:* 2 {{"The specified type does not meet the requirements of Cpp17MoveInsertable"}}
+ {
+
+ std::vector<BadUserNoCookie<1> > x;
+ x.emplace_back();
+ }
+ {
+ std::vector<BadUserNoCookie<2>> x;
+ BadUserNoCookie<2> c;
+ x.push_back(c);
+ }
+ return 0;
+}
OpenPOWER on IntegriCloud