summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create')
-rw-r--r--libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp44
-rw-r--r--libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp17
-rw-r--r--libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp17
-rw-r--r--libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp17
-rw-r--r--libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp17
-rw-r--r--libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp32
6 files changed, 144 insertions, 0 deletions
diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp
new file mode 100644
index 00000000000..30b4ecb94e1
--- /dev/null
+++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+#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()
+{
+ {
+ 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 );
+ }
+}
diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp
new file mode 100644
index 00000000000..00987919413
--- /dev/null
+++ b/libcxx/test/std/utilities/smartptr/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/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp
new file mode 100644
index 00000000000..cc94e9ab3aa
--- /dev/null
+++ b/libcxx/test/std/utilities/smartptr/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/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp
new file mode 100644
index 00000000000..cfdc2e1d886
--- /dev/null
+++ b/libcxx/test/std/utilities/smartptr/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/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp
new file mode 100644
index 00000000000..07aa659bd9b
--- /dev/null
+++ b/libcxx/test/std/utilities/smartptr/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/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp
new file mode 100644
index 00000000000..ace2e4fc713
--- /dev/null
+++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03, c++11
+#include <memory>
+#include <string>
+#include <cassert>
+
+int main()
+{
+ {
+ 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" );
+ }
+}
OpenPOWER on IntegriCloud