summaryrefslogtreecommitdiffstats
path: root/libcxx/test
diff options
context:
space:
mode:
authorMarshall Clow <mclow@qualcomm.com>2013-07-01 18:16:03 +0000
committerMarshall Clow <mclow@qualcomm.com>2013-07-01 18:16:03 +0000
commit28d8ba5f79e986ebfdc29fcb67ecaf3a3c823db0 (patch)
tree0b18bc0da611f2c35de7efcd2a1391aecb83cb01 /libcxx/test
parent7a9fcdf6fb84b4d8db49eb0a8488b81155bffb2a (diff)
downloadbcm5719-llvm-28d8ba5f79e986ebfdc29fcb67ecaf3a3c823db0.tar.gz
bcm5719-llvm-28d8ba5f79e986ebfdc29fcb67ecaf3a3c823db0.zip
Implement n3656 - make_unique. Thanks to Howard for the review and suggestions.
llvm-svn: 185352
Diffstat (limited to 'libcxx/test')
-rw-r--r--libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp45
-rw-r--r--libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp17
-rw-r--r--libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp17
-rw-r--r--libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp17
-rw-r--r--libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp17
-rw-r--r--libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp33
6 files changed, 146 insertions, 0 deletions
diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp
new file mode 100644
index 00000000000..b2fb58f529f
--- /dev/null
+++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <memory>
+#include <string>
+#include <cassert>
+
+// The only way to create an unique_ptr<T[]> is to default construct them.
+
+class foo {
+public:
+ foo () : val_(3) {}
+ int get () const { return val_; }
+private:
+ int val_;
+ };
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ {
+ auto p1 = std::make_unique<int[]>(5);
+ for ( int i = 0; i < 5; ++i )
+ assert ( p1[i] == 0 );
+ }
+
+ {
+ auto p2 = std::make_unique<std::string[]>(5);
+ for ( int i = 0; i < 5; ++i )
+ assert ( p2[i].size () == 0 );
+ }
+
+ {
+ auto p3 = std::make_unique<foo[]>(7);
+ for ( int i = 0; i < 7; ++i )
+ assert ( p3[i].get () == 3 );
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp
new file mode 100644
index 00000000000..00987919413
--- /dev/null
+++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <memory>
+#include <string>
+#include <cassert>
+
+int main()
+{
+ auto up1 = std::make_unique<std::string[]>("error"); // doesn't compile - no bound
+}
diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp
new file mode 100644
index 00000000000..cc94e9ab3aa
--- /dev/null
+++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <memory>
+#include <string>
+#include <cassert>
+
+int main()
+{
+ auto up2 = std::make_unique<int[]>(10, 20, 30, 40);
+}
diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp
new file mode 100644
index 00000000000..cfdc2e1d886
--- /dev/null
+++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <memory>
+#include <string>
+#include <cassert>
+
+int main()
+{
+ auto up3 = std::make_unique<int[5]>(); // this is deleted
+}
diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp
new file mode 100644
index 00000000000..26eb59bbfd7
--- /dev/null
+++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp
@@ -0,0 +1,17 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <memory>
+#include <string>
+#include <cassert>
+
+int main()
+{
+ auto up4 = std::make_unique<int[5]>(11, 22, 33, 44, 55); // deleted
+}
diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp
new file mode 100644
index 00000000000..7326ed22655
--- /dev/null
+++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <memory>
+#include <string>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ {
+ std::unique_ptr<int> p1 = std::make_unique<int>(1);
+ assert ( *p1 == 1 );
+ p1 = std::make_unique<int> ();
+ assert ( *p1 == 0 );
+ }
+
+ {
+ std::unique_ptr<std::string> p2 = std::make_unique<std::string> ( "Meow!" );
+ assert ( *p2 == "Meow!" );
+ p2 = std::make_unique<std::string> ();
+ assert ( *p2 == "" );
+ p2 = std::make_unique<std::string> ( 6, 'z' );
+ assert ( *p2 == "zzzzzz" );
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
OpenPOWER on IntegriCloud