From 2561885f574ce7aedee4d30f3dbc6bfb09d64c06 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 15 Apr 2017 05:28:06 +0000 Subject: [PATCH] Rewrite and cleanup unique_ptr tests. This patch almost entirely rewrites the unique_ptr tests. There are a couple of reasons for this: A) Most of the *.fail.cpp tests were either incorrect or could be better written as a *.pass.cpp test that uses to check if certain operations are valid (Ex. Using static_assert(!std::is_copy_constructible_v) instead of writing a failure test). B) [unique.ptr.runtime] has very poor test coverage. Many of the constructors and assignment operators have to tests at all. The special members that have tests have very few test cases and are typically way out of date. C) The tests for [unique.ptr.single] and [unique.ptr.runtime] are largely duplicates of each other. This means common requirements have two different sets of tests in two different test files. This makes the tests harder to maintain than if there was a single copy. To address (A) this patch changes almost all of the *.fail.cpp tests into .pass.cpp tests using type traits; Allowing the *.fail.cpp tests to be removed. The address (B) and (C) the tests for [unique.ptr.single] and [unique.ptr.runtime] have been combined into a single directory, allowing both specializations to share common tests. Tests specific to the single/runtime specializations are given the suffix "*.single.pass.cpp" or "*.runtime.pass.cpp". Finally the unique.ptr test have been moved into the correct directory according to the standard. Specifically they have been removed from "utilities/memory" into "utilities/smartptr". PS. This patch also adds newly written tests for upcoming unique_ptr changes/fixes. However since these tests don't currently pass they are guarded by the macro TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES. This allows other STL's to validate the tests before libc++ implements the changes. The relevant libc++ changes should land in the next week. llvm-svn: 300388 --- .../unique.ptr/unique.ptr.runtime/move01.fail.cpp | 28 -- .../unique.ptr/unique.ptr.runtime/move01.pass.cpp | 79 ------ .../unique.ptr/unique.ptr.runtime/move02.fail.cpp | 39 --- .../unique.ptr/unique.ptr.runtime/move03.fail.cpp | 57 ---- .../unique.ptr/unique.ptr.runtime/move04.fail.cpp | 57 ---- .../unique.ptr.runtime/move_convert01.fail.cpp | 57 ---- .../unique.ptr.runtime/move_convert02.fail.cpp | 61 ---- .../unique.ptr.runtime/move_convert03.fail.cpp | 62 ----- .../unique.ptr.runtime/move_convert04.fail.cpp | 57 ---- .../unique.ptr.runtime/move_convert05.fail.cpp | 61 ---- .../unique.ptr.runtime/move_convert06.fail.cpp | 62 ----- .../unique.ptr.runtime/move_convert07.fail.cpp | 56 ---- .../unique.ptr.runtime/move_convert08.fail.cpp | 60 ---- .../unique.ptr.runtime/move_convert09.fail.cpp | 62 ----- .../unique.ptr.runtime/null_asgn.pass.cpp | 41 --- .../unique.ptr.runtime/null_ctor.pass.cpp | 55 ---- .../unique.ptr.runtime/nullptr_asgn.pass.cpp | 41 --- .../unique.ptr.runtime/pointer_type.pass.cpp | 34 --- .../unique.ptr.runtime.ctor/default.pass.cpp | 50 ---- .../unique.ptr.runtime.ctor/default01.fail.cpp | 39 --- .../unique.ptr.runtime.ctor/default02.fail.cpp | 30 -- .../unique.ptr.runtime.ctor/default03.fail.cpp | 23 -- .../default_allows_incomplete.pass.cpp | 80 ------ .../unique.ptr.runtime.ctor/move01.fail.cpp | 42 --- .../unique.ptr.runtime.ctor/move01.pass.cpp | 70 ----- .../unique.ptr.runtime.ctor/move02.fail.cpp | 42 --- .../unique.ptr.runtime.ctor/move02.pass.cpp | 72 ----- .../unique.ptr.runtime.ctor/move03.fail.cpp | 55 ---- .../unique.ptr.runtime.ctor/move04.fail.cpp | 55 ---- .../move_convert01.fail.cpp | 57 ---- .../move_convert02.fail.cpp | 61 ---- .../move_convert03.fail.cpp | 78 ------ .../move_convert04.fail.cpp | 57 ---- .../move_convert05.fail.cpp | 61 ---- .../move_convert06.fail.cpp | 78 ------ .../move_convert07.fail.cpp | 57 ---- .../move_convert08.fail.cpp | 61 ---- .../move_convert09.fail.cpp | 78 ------ .../move_convert10.fail.cpp | 57 ---- .../move_convert11.fail.cpp | 61 ---- .../move_convert12.fail.cpp | 78 ------ .../move_convert13.fail.cpp | 57 ---- .../move_convert14.fail.cpp | 61 ---- .../move_convert15.fail.cpp | 78 ------ .../move_convert16.fail.cpp | 57 ---- .../move_convert17.fail.cpp | 61 ---- .../move_convert18.fail.cpp | 78 ------ .../unique.ptr.runtime.ctor/nullptr.pass.cpp | 46 --- .../unique.ptr.runtime.ctor/pointer01.fail.cpp | 36 --- .../unique.ptr.runtime.ctor/pointer01.pass.cpp | 63 ----- .../unique.ptr.runtime.ctor/pointer02.fail.cpp | 29 -- .../unique.ptr.runtime.ctor/pointer02.pass.cpp | 95 ------- .../unique.ptr.runtime.ctor/pointer03.fail.cpp | 23 -- .../unique.ptr.runtime.ctor/pointer04.fail.cpp | 67 ----- .../pointer_deleter01.pass.cpp | 51 ---- .../pointer_deleter02.pass.cpp | 64 ----- .../pointer_deleter03.pass.cpp | 65 ----- .../pointer_deleter04.fail.cpp | 33 --- .../pointer_deleter04.pass.cpp | 63 ----- .../pointer_deleter05.fail.cpp | 58 ---- .../unique.ptr.runtime.modifiers/release.pass.cpp | 27 -- .../unique.ptr.runtime.modifiers/reset1.pass.cpp | 50 ---- .../unique.ptr.runtime.modifiers/reset2.fail.cpp | 64 ----- .../unique.ptr.runtime.modifiers/swap.pass.cpp | 56 ---- .../dereference.fail.cpp | 23 -- .../get_deleter.pass.cpp | 58 ---- .../unique.ptr.runtime.observers/index.pass.cpp | 47 ---- .../unique.ptr.single/pointer_type.pass.cpp | 55 ---- .../unique.ptr.single.asgn/move01.fail.cpp | 29 -- .../unique.ptr.single.asgn/move01.pass.cpp | 75 ----- .../unique.ptr.single.asgn/move02.fail.cpp | 33 --- .../unique.ptr.single.asgn/move03.fail.cpp | 33 --- .../unique.ptr.single.asgn/move04.fail.cpp | 36 --- .../unique.ptr.single.asgn/move_convert.pass.cpp | 89 ------ .../unique.ptr.single.asgn/move_convert01.fail.cpp | 42 --- .../unique.ptr.single.asgn/move_convert02.fail.cpp | 43 --- .../unique.ptr.single.asgn/move_convert03.fail.cpp | 47 ---- .../unique.ptr.single.asgn/move_convert04.fail.cpp | 43 --- .../unique.ptr.single.asgn/move_convert05.fail.cpp | 61 ---- .../unique.ptr.single.asgn/move_convert06.fail.cpp | 62 ----- .../unique.ptr.single.asgn/move_convert13.fail.cpp | 36 --- .../unique.ptr.single.ctor/auto_pointer01.fail.cpp | 67 ----- .../unique.ptr.single.ctor/auto_pointer02.fail.cpp | 61 ---- .../unique.ptr.single.ctor/default.pass.cpp | 91 ------ .../unique.ptr.single.ctor/default01.fail.cpp | 35 --- .../unique.ptr.single.ctor/default02.fail.cpp | 29 -- .../unique.ptr.single.ctor/default03.fail.cpp | 23 -- .../unique.ptr.single.ctor/move.pass.cpp | 140 ---------- .../unique.ptr.single.ctor/move01.fail.cpp | 42 --- .../unique.ptr.single.ctor/move02.fail.cpp | 42 --- .../unique.ptr.single.ctor/move03.fail.cpp | 55 ---- .../unique.ptr.single.ctor/move04.fail.cpp | 55 ---- .../unique.ptr.single.ctor/move_convert.pass.cpp | 171 ------------ .../unique.ptr.single.ctor/move_convert01.fail.cpp | 56 ---- .../unique.ptr.single.ctor/move_convert02.fail.cpp | 62 ----- .../unique.ptr.single.ctor/move_convert03.fail.cpp | 79 ------ .../unique.ptr.single.ctor/move_convert04.fail.cpp | 58 ---- .../unique.ptr.single.ctor/move_convert05.fail.cpp | 51 ---- .../unique.ptr.single.ctor/move_convert06.fail.cpp | 79 ------ .../unique.ptr.single.ctor/move_convert07.fail.cpp | 58 ---- .../unique.ptr.single.ctor/move_convert08.fail.cpp | 86 ------ .../unique.ptr.single.ctor/move_convert09.fail.cpp | 79 ------ .../unique.ptr.single.ctor/move_convert10.fail.cpp | 58 ---- .../unique.ptr.single.ctor/move_convert11.fail.cpp | 86 ------ .../unique.ptr.single.ctor/move_convert12.fail.cpp | 79 ------ .../unique.ptr.single.ctor/move_convert13.fail.cpp | 35 --- .../unique.ptr.single.ctor/nullptr.pass.cpp | 46 --- .../unique.ptr.single.ctor/pointer.pass.cpp | 163 ----------- .../unique.ptr.single.ctor/pointer01.fail.cpp | 35 --- .../unique.ptr.single.ctor/pointer02.fail.cpp | 29 -- .../unique.ptr.single.ctor/pointer03.fail.cpp | 23 -- .../pointer_deleter.pass.cpp | 123 --------- .../unique.ptr.single.modifiers/release.pass.cpp | 27 -- .../unique.ptr.single.modifiers/reset1.pass.cpp | 50 ---- .../unique.ptr.single.modifiers/swap.pass.cpp | 59 ---- .../unique.ptr.single.observers/get.pass.cpp | 24 -- .../std/utilities/smartptr/unique.ptr/README.TXT | 16 ++ .../unique.ptr}/nothing_to_do.pass.cpp | 0 .../unique.ptr.class/pointer_type.pass.cpp | 61 ++++ .../unique.ptr.class/unique.ptr.asgn/move.pass.cpp | 119 ++++++++ .../unique.ptr.asgn/move_convert.runtime.pass.cpp | 124 +++++++++ .../unique.ptr.asgn/move_convert.single.pass.cpp | 145 ++++++++++ .../unique.ptr.asgn}/null.pass.cpp | 36 ++- .../unique.ptr.asgn}/nullptr.pass.cpp | 33 ++- .../unique.ptr.ctor}/auto_pointer.pass.cpp | 75 +++-- .../unique.ptr.ctor/default.pass.cpp | 109 ++++++++ .../unique.ptr.class/unique.ptr.ctor/move.pass.cpp | 151 ++++++++++ .../unique.ptr.ctor/move_convert.runtime.pass.cpp | 80 ++++++ .../unique.ptr.ctor/move_convert.single.pass.cpp | 222 +++++++++++++++ .../unique.ptr.class/unique.ptr.ctor/null.pass.cpp | 74 +++++ .../unique.ptr.ctor/nullptr.pass.cpp | 117 ++++++++ .../unique.ptr.ctor/pointer.pass.cpp | 167 +++++++++++ .../unique.ptr.ctor/pointer_deleter.fail.cpp} | 15 +- .../unique.ptr.ctor/pointer_deleter.pass.cpp | 307 +++++++++++++++++++++ .../unique.ptr.dtor}/null.pass.cpp | 36 +-- .../unique.ptr.modifiers/release.pass.cpp | 48 ++++ .../unique.ptr.modifiers/reset.pass.cpp | 51 ++++ .../unique.ptr.modifiers/reset.runtime.fail.cpp} | 31 +-- .../unique.ptr.modifiers/reset.single.pass.cpp} | 40 +-- .../unique.ptr.modifiers}/reset_self.pass.cpp | 14 +- .../unique.ptr.modifiers/swap.pass.cpp | 80 ++++++ .../dereference.runtime.fail.cpp} | 25 +- .../dereference.single.pass.cpp} | 7 +- .../unique.ptr.observers/explicit_bool.pass.cpp | 66 +++++ .../unique.ptr.observers/get.pass.cpp | 51 ++++ .../unique.ptr.observers}/get_deleter.pass.cpp | 15 +- .../op_arrow.runtime.fail.cpp} | 20 +- .../unique.ptr.observers/op_arrow.single.pass.cpp} | 14 +- .../op_subscript.runtime.pass.cpp} | 43 +-- .../op_subscript.single.fail.cpp} | 12 +- .../unique.ptr.create/make_unique.array.pass.cpp | 0 .../unique.ptr.create/make_unique.array1.fail.cpp | 0 .../unique.ptr.create/make_unique.array2.fail.cpp | 0 .../unique.ptr.create/make_unique.array3.fail.cpp | 0 .../unique.ptr.create/make_unique.array4.fail.cpp | 0 .../unique.ptr.create/make_unique.single.pass.cpp | 0 .../unique.ptr.dltr/nothing_to_do.pass.cpp | 0 .../unique.ptr.dltr.dflt/convert_ctor.pass.cpp | 0 .../unique.ptr.dltr.dflt/default.pass.cpp | 0 .../unique.ptr.dltr.dflt/incomplete.fail.cpp | 0 .../unique.ptr.dltr.dflt/void.fail.cpp | 0 .../unique.ptr.dltr.dflt1/convert_ctor.fail.cpp | 0 .../unique.ptr.dltr.dflt1/convert_ctor.pass.cpp | 0 .../unique.ptr.dltr.dflt1/default.pass.cpp | 0 .../unique.ptr.dltr.dflt1/incomplete.fail.cpp | 0 .../nothing_to_do.pass.cpp | 0 .../unique.ptr.special/cmp_nullptr.pass.cpp | 0 .../unique.ptr/unique.ptr.special/eq.pass.cpp | 0 .../unique.ptr/unique.ptr.special/rel.pass.cpp | 0 .../unique.ptr/unique.ptr.special/swap.pass.cpp | 0 libcxx/test/support/test_workarounds.h | 8 + libcxx/test/support/unique_ptr_test_helper.h | 164 +++++++++++ 172 files changed, 2359 insertions(+), 6878 deletions(-) delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default_allows_incomplete.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp delete mode 100644 libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/README.TXT rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general => smartptr/unique.ptr}/nothing_to_do.pass.cpp (100%) create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/pointer_type.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.runtime.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.single.pass.cpp rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn => smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn}/null.pass.cpp (57%) rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn => smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn}/nullptr.pass.cpp (59%) rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor => smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor}/auto_pointer.pass.cpp (50%) create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.runtime.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.single.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/null.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp => smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.fail.cpp} (59%) create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.pass.cpp rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor => smartptr/unique.ptr/unique.ptr.class/unique.ptr.dtor}/null.pass.cpp (57%) create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/release.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.pass.cpp rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp => smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.runtime.fail.cpp} (57%) rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp => smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.single.pass.cpp} (67%) rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers => smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers}/reset_self.pass.cpp (76%) create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/swap.pass.cpp rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp => smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.runtime.fail.cpp} (57%) rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp => smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.single.pass.cpp} (85%) create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/explicit_bool.pass.cpp create mode 100644 libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get.pass.cpp rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers => smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers}/get_deleter.pass.cpp (80%) rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp => smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.runtime.fail.cpp} (51%) rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp => smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.single.pass.cpp} (79%) rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp => smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.runtime.pass.cpp} (50%) rename libcxx/test/std/utilities/{memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp => smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.single.fail.cpp} (57%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp (100%) rename libcxx/test/std/utilities/{memory/unique.ptr => smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general}/nothing_to_do.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.special/eq.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.special/rel.pass.cpp (100%) rename libcxx/test/std/utilities/{memory => smartptr}/unique.ptr/unique.ptr.special/swap.pass.cpp (100%) create mode 100644 libcxx/test/support/unique_ptr_test_helper.h diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp deleted file mode 100644 index ed94c1a..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp +++ /dev/null @@ -1,28 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -#include - -#include "test_macros.h" - -int main() -{ - std::unique_ptr s, s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}} -#else - s2 = s; // expected-error {{'operator=' is a private member of 'std::__1::unique_ptr}} -#endif -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp deleted file mode 100644 index a29c527..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -// test move assignment. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr s1(new A[3]); - A* p = s1.get(); - assert(A::count == 3); - std::unique_ptr s2(new A[2]); - assert(A::count == 5); - s2 = std::move(s1); - assert(A::count == 3); - assert(s2.get() == p); - assert(s1.get() == 0); - } - assert(A::count == 0); - { - std::unique_ptr > s1(new A[4], Deleter(5)); - A* p = s1.get(); - assert(A::count == 4); - std::unique_ptr > s2(new A[5]); - assert(A::count == 9); - s2 = std::move(s1); - assert(s2.get() == p); - assert(s1.get() == 0); - assert(A::count == 4); - assert(s2.get_deleter().state() == 5); - assert(s1.get_deleter().state() == 0); - } - assert(A::count == 0); - { - CDeleter d1(5); - std::unique_ptr&> s1(new A[6], d1); - A* p = s1.get(); - assert(A::count == 6); - CDeleter d2(6); - std::unique_ptr&> s2(new A[3], d2); - assert(A::count == 9); - s2 = std::move(s1); - assert(A::count == 6); - assert(s2.get() == p); - assert(s1.get() == 0); - assert(d1.state() == 5); - assert(d2.state() == 5); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp deleted file mode 100644 index 6e13873..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp +++ /dev/null @@ -1,39 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -#include -#include -#include - -// Can't copy from const lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - const std::unique_ptr s(new A[3]); - std::unique_ptr s2; - s2 = s; - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp deleted file mode 100644 index 3712a27..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -#include -#include -#include - -// Can't copy from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete p;} -}; - -int main() -{ - { - std::unique_ptr s(new A); - A* p = s.get(); - std::unique_ptr s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp deleted file mode 100644 index 4e85e5b..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -#include -#include -#include - -// test move ctor. Can't copy from const lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete p;} -}; - -int main() -{ - { - const std::unique_ptr s(new A); - A* p = s.get(); - std::unique_ptr s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp deleted file mode 100644 index 9461958..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include -#include -#include - -// Can't assign from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp deleted file mode 100644 index 78caaa4..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from lvalue - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - boost::unique_ptr > s(new B); - A* p = s.get(); - boost::unique_ptr > s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp deleted file mode 100644 index b9693b8..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from lvalue - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - Deleter db(5); - boost::unique_ptr&> s(new B, db); - A* p = s.get(); - Deleter da(6); - boost::unique_ptr&> s2(new A, da); - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp deleted file mode 100644 index 970beb5..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include -#include -#include - -// Can't assign from const lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const boost::unique_ptr s(new B); - A* p = s.get(); - boost::unique_ptr s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp deleted file mode 100644 index 8976731..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from const lvalue - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const boost::unique_ptr > s(new B); - A* p = s.get(); - boost::unique_ptr > s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp deleted file mode 100644 index 1081cd1..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from const lvalue - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - Deleter db(5); - const boost::unique_ptr&> s(new B, db); - A* p = s.get(); - Deleter da(6); - boost::unique_ptr&> s2(new A, da); - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp deleted file mode 100644 index 65ee269..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp +++ /dev/null @@ -1,56 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - boost::unique_ptr s(new B); - A* p = s.get(); - boost::unique_ptr s2(new A); - assert(A::count == 2); - s2 = boost::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp deleted file mode 100644 index 310be99..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp +++ /dev/null @@ -1,60 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - boost::unique_ptr > s(new B); - A* p = s.get(); - boost::unique_ptr > s2(new A); - assert(A::count == 2); - s2 = (boost::move(s)); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp deleted file mode 100644 index eb48e9c..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -// test converting move assignment with reference deleters - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - Deleter db(5); - boost::unique_ptr&> s(new B, db); - A* p = s.get(); - Deleter da(6); - boost::unique_ptr&> s2(new A, da); - s2 = boost::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp deleted file mode 100644 index e2d7956..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -#include -#include - -// test assignment from null - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr s2(new A); - assert(A::count == 1); - s2 = 0; - assert(A::count == 0); - assert(s2.get() == 0); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp deleted file mode 100644 index 5038997..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// The deleter is not called if get() == 0 - -#include -#include - -#include "test_macros.h" - -class Deleter -{ - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(0) {} - - int state() const {return state_;} - - void operator()(void*) {++state_;} -}; - -int main() -{ - Deleter d; - assert(d.state() == 0); - { - std::unique_ptr p(nullptr, d); - assert(p.get() == 0); - assert(&p.get_deleter() == &d); - } -#if defined(_LIBCPP_VERSION) - { - // The standard only requires the constructor accept nullptr, but libc++ - // also supports the literal 0. - std::unique_ptr p(0, d); - assert(p.get() == 0); - assert(&p.get_deleter() == &d); - } -#endif - assert(d.state() == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp deleted file mode 100644 index 30ecdde..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -#include -#include - -// test assignment from null - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr s2(new A[3]); - assert(A::count == 3); - s2 = nullptr; - assert(A::count == 0); - assert(s2.get() == 0); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp deleted file mode 100644 index e7ad6ad..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr::pointer type - -#include -#include - -struct Deleter -{ - struct pointer {}; -}; - -int main() -{ - { - typedef std::unique_ptr P; - static_assert((std::is_same::value), ""); - } - { - typedef std::unique_ptr P; - static_assert((std::is_same::value), ""); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default.pass.cpp deleted file mode 100644 index 43ad296..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default.pass.cpp +++ /dev/null @@ -1,50 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr default ctor - -// default unique_ptr ctor should only require default Deleter ctor - -#include -#include -#include "test_macros.h" - -#if defined(_LIBCPP_VERSION) && TEST_STD_VER >= 11 -_LIBCPP_SAFE_STATIC std::unique_ptr global_static_unique_ptr; -#endif - -class Deleter { - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(5) {} - - int state() const { return state_; } - - void operator()(void*) {} -}; - -int main() { - { - std::unique_ptr p; - assert(p.get() == 0); - } - { - std::unique_ptr p; - assert(p.get() == 0); - assert(p.get_deleter().state() == 5); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp deleted file mode 100644 index e4d6391..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp +++ /dev/null @@ -1,39 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr default ctor - -// default unique_ptr ctor should require default Deleter ctor - -#include -#include "test_macros.h" - -class Deleter { - Deleter() {} - -public: - Deleter(Deleter&) {} - Deleter& operator=(Deleter&) { return *this; } - - void operator()(void*) const {} -}; - -int main() { -#if TEST_STD_VER >= 11 - // expected-error@memory:* {{call to implicitly-deleted default constructor}} - // expected-note@memory:* {{implicitly deleted because base class 'Deleter' has an inaccessible default constructor}} -#else - // expected-error@memory:* {{base class 'Deleter' has private default constructor}} -#endif - std::unique_ptr p; // expected-note {{requested here}} -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp deleted file mode 100644 index 82b8494..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr default ctor - -// default unique_ptr ctor should require non-reference Deleter ctor - -#include - -class Deleter -{ -public: - - void operator()(void*) {} -}; - -int main() -{ - std::unique_ptr p; -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp deleted file mode 100644 index 74d24fd..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr default ctor - -// default unique_ptr ctor should require non-pointer Deleter - -#include - -int main() -{ - std::unique_ptr p; -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default_allows_incomplete.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default_allows_incomplete.pass.cpp deleted file mode 100644 index 38c2f1b..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default_allows_incomplete.pass.cpp +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test default unique_ptr ctor - -// default unique_ptr ctor shouldn't require complete type - -#include -#include - -struct A; - -class Deleter { - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(5) {} - - int state() const { return state_; } - - void operator()(A* p); -}; - -void check(int i); - -template > -struct B { - std::unique_ptr a_; - B(); - ~B(); - - A* get() const { return a_.get(); } - D& get_deleter() { return a_.get_deleter(); } -}; - -int main() { - { - B<> s; - assert(s.get() == 0); - } - check(0); - { - B s; - assert(s.get() == 0); - assert(s.get_deleter().state() == 5); - } - check(0); -} - -struct A { - static int count; - A() { ++count; } - A(const A&) { ++count; } - ~A() { --count; } -}; - -int A::count = 0; - -void Deleter::operator()(A* p) { delete p; } - -void check(int i) { assert(A::count == i); } - -template -B::B() {} - -template -B::~B() {} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp deleted file mode 100644 index bc49a0e..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -#include -#include - -// test move ctor. Can't copy from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr s(new A[3]); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp deleted file mode 100644 index 8a1f2ce9..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp +++ /dev/null @@ -1,70 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -// test move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr s(new A[3]); - A* p = s.get(); - std::unique_ptr s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 3); - } - assert(A::count == 0); - { - std::unique_ptr > s(new A[3], Deleter(5)); - A* p = s.get(); - std::unique_ptr > s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 3); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - { - NCDeleter d; - std::unique_ptr&> s(new A[3], d); - A* p = s.get(); - std::unique_ptr&> s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 3); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp deleted file mode 100644 index 8e44c78..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -// test move ctor. Can't copy from const lvalue - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - const std::unique_ptr s(new A[3]); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp deleted file mode 100644 index f758b08..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp +++ /dev/null @@ -1,72 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -// test move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. - -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - - -std::unique_ptr -source1() -{ - return std::unique_ptr(new A[3]); -} - -void sink1(std::unique_ptr) -{ -} - -std::unique_ptr > -source2() -{ - return std::unique_ptr >(new A[3]); -} - -void sink2(std::unique_ptr >) -{ -} - -std::unique_ptr&> -source3() -{ - static NCDeleter d; - return std::unique_ptr&>(new A[3], d); -} - -void sink3(std::unique_ptr&>) -{ -} - -int main() -{ - sink1(source1()); - sink2(source2()); - sink3(source3()); - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp deleted file mode 100644 index c952cf2..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -// test move ctor. Can't copy from lvalue - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - std::unique_ptr s(new A[3]); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp deleted file mode 100644 index 0d091ff..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -// test move ctor. Can't copy from const lvalue - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - const std::unique_ptr s(new A[3]); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp deleted file mode 100644 index d175fbf..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp deleted file mode 100644 index 1d3dd85..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr > s(new B); - A* p = s.get(); - std::unique_ptr > s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp deleted file mode 100644 index 36ad75d..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter d; - std::unique_ptr&> s(new B, d); - A* p = s.get(); - std::unique_ptr&> s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp deleted file mode 100644 index 3a19bde..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// implicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp deleted file mode 100644 index 2253766..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Implicit version - -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr > s(new B); - A* p = s.get(); - std::unique_ptr > s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp deleted file mode 100644 index fba8951..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter d; - std::unique_ptr&> s(new B, d); - A* p = s.get(); - std::unique_ptr&> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp deleted file mode 100644 index 24c6469..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp deleted file mode 100644 index 2c8f281..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const std::unique_ptr > s(new B); - A* p = s.get(); - std::unique_ptr > s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp deleted file mode 100644 index e4cbef5..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter d; - const std::unique_ptr&> s(new B, d); - A* p = s.get(); - std::unique_ptr&> s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp deleted file mode 100644 index 73423d1..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// implicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp deleted file mode 100644 index a7d853d..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Implicit version - -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const std::unique_ptr > s(new B); - A* p = s.get(); - std::unique_ptr > s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp deleted file mode 100644 index fdb0882..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter d; - const std::unique_ptr&> s(new B, d); - A* p = s.get(); - std::unique_ptr&> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp deleted file mode 100644 index d9ef8e9..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2(std::move(s)); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp deleted file mode 100644 index 431c8bf..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr > s(new B); - A* p = s.get(); - std::unique_ptr > s2(std::move(s)); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp deleted file mode 100644 index 9325d07..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter d; - std::unique_ptr&> s(new B, d); - A* p = s.get(); - std::unique_ptr&> s2(std::move(s)); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp deleted file mode 100644 index b090e59..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// implicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp deleted file mode 100644 index 6e214f1..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Implicit version - -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr > s(new B); - A* p = s.get(); - std::unique_ptr > s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp deleted file mode 100644 index d1c0e8a..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter d; - std::unique_ptr&> s(new B, d); - A* p = s.get(); - std::unique_ptr&> s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp deleted file mode 100644 index 9a8c175..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// unique_ptr(nullptr_t); - -#include -#include - -// default unique_ptr ctor should only require default Deleter ctor -class Deleter -{ - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(void*) {} -}; - -int main() -{ - { - std::unique_ptr p(nullptr); - assert(p.get() == 0); - } - { - std::unique_ptr p(nullptr); - assert(p.get() == 0); - assert(p.get_deleter().state() == 5); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp deleted file mode 100644 index 4c31611..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -// unique_ptr(pointer) ctor should require default Deleter ctor - -#include - -class Deleter -{ - - Deleter() {} - -public: - - Deleter(Deleter&) {} - Deleter& operator=(Deleter&) {} - - void operator()(void*) const {} -}; - -int main() -{ - std::unique_ptr p(new int); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp deleted file mode 100644 index dab42f2..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -// unique_ptr(pointer) ctor should only require default Deleter ctor - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - A* p = new A[3]; - assert(A::count == 3); - std::unique_ptr s(p); - assert(s.get() == p); - } - assert(A::count == 0); - { - A* p = new A[3]; - assert(A::count == 3); - std::unique_ptr s(p); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp deleted file mode 100644 index af7f27f..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -#include - -// unique_ptr(pointer) ctor should require non-reference Deleter ctor -class Deleter -{ -public: - - void operator()(void*) {} -}; - -int main() -{ - std::unique_ptr p(new int); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp deleted file mode 100644 index 1afb1c3..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp +++ /dev/null @@ -1,95 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -// unique_ptr(pointer) ctor shouldn't require complete type - -#include -#include - -struct A; - -class Deleter -{ - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p); -}; - -void check(int i); - -template > -struct B -{ - std::unique_ptr a_; - explicit B(A*); - ~B(); - - A* get() const {return a_.get();} - D& get_deleter() {return a_.get_deleter();} -}; - -A* get(); - -int main() -{ - { - A* p = get(); - check(3); - B<> s(p); - assert(s.get() == p); - } - check(0); - { - A* p = get(); - check(3); - B s(p); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - } - check(0); -} - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -A* get() {return new A[3];} - -void Deleter::operator()(A* p) {delete [] p;} - -void check(int i) -{ - assert(A::count == i); -} - -template -B::B(A* a) : a_(a) {} - -template -B::~B() {} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp deleted file mode 100644 index 31f7ce3..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -// unique_ptr(pointer) ctor should require non-pointer Deleter - -#include - -int main() -{ - std::unique_ptr p(new int); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp deleted file mode 100644 index 591144f..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -// unique_ptr(pointer) ctor should not work with derived pointers - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -class Deleter -{ - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - B* p = new B[3]; - std::unique_ptr s(p); - } - { - B* p = new B[3]; - std::unique_ptr s(p); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp deleted file mode 100644 index 480dc08..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp +++ /dev/null @@ -1,51 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter - -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - A* p = new A[3]; - assert(A::count == 3); - std::unique_ptr > s(p, Deleter()); - assert(s.get() == p); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - - { // LWG#2520 says that nullptr is a valid input as well as null -#ifdef _LIBCPP_VERSION - std::unique_ptr > s1(NULL, Deleter()); -#endif - std::unique_ptr > s2(nullptr, Deleter()); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp deleted file mode 100644 index a92fdbc..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr(pointer, d) requires CopyConstructible deleter - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - A* p = new A[3]; - assert(A::count == 3); - Deleter d; - std::unique_ptr s(p, d); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - d.set_state(6); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); - { - Deleter d; - std::unique_ptr s(nullptr, d); - assert(s.get() == nullptr); - assert(s.get_deleter().state() == 5); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp deleted file mode 100644 index dd27401..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp +++ /dev/null @@ -1,65 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr(pointer, d) does not requires CopyConstructible deleter - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - - Deleter(const Deleter&); - Deleter& operator=(const Deleter&); -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - A* p = new A[3]; - assert(A::count == 3); - Deleter d; - std::unique_ptr s(p, d); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - d.set_state(6); - assert(s.get_deleter().state() == 6); - } - assert(A::count == 0); - { - Deleter d; - std::unique_ptr s(nullptr, d); - assert(s.get() == nullptr); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp deleted file mode 100644 index 9d3f940..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// XFAIL: c++98, c++03 - -// - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr(pointer, D()) should not compile - -#include - -class Deleter -{ -public: - Deleter() {} - void operator()(int* p) const {delete [] p;} -}; - -int main() -{ - int* p = nullptr; - std::unique_ptr s(p, Deleter()); // expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}} -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp deleted file mode 100644 index 02f44d3..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr(pointer, d) does not requires CopyConstructible deleter - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - - Deleter(const Deleter&); - Deleter& operator=(const Deleter&); -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(A* p) const {delete [] p;} -}; - -int main() -{ - { - A* p = new A[3]; - assert(A::count == 3); - Deleter d; - std::unique_ptr s(p, d); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); - { - Deleter d; - std::unique_ptr s(nullptr, d); - assert(s.get() == nullptr); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp deleted file mode 100644 index 0e03a7d..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr(pointer, deleter) should not work with derived pointers - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -class Deleter -{ - int state_; - -public: - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - B* p = new B[3]; - std::unique_ptr s(p, Deleter()); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp deleted file mode 100644 index d79a4e3..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp +++ /dev/null @@ -1,27 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test release - -#include -#include - -int main() -{ - std::unique_ptr p(new int[3]); - int* i = p.get(); - int* j = p.release(); - assert(p.get() == 0); - assert(i == j); - delete [] j; -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp deleted file mode 100644 index 195d877..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp +++ /dev/null @@ -1,50 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test reset - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr p(new A[3]); - assert(A::count == 3); - A* i = p.get(); - assert(i != nullptr); - p.reset(); - assert(A::count == 0); - assert(p.get() == 0); - } - assert(A::count == 0); - { - std::unique_ptr p(new A[4]); - assert(A::count == 4); - A* i = p.get(); - assert(i != nullptr); - p.reset(new A[5]); - assert(A::count == 5); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp deleted file mode 100644 index bca6cb2..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test reset - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr p(new A); - assert(A::count == 1); - assert(B::count == 0); - A* i = p.get(); - p.reset(new B); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); - { - std::unique_ptr p(new B); - assert(A::count == 1); - assert(B::count == 1); - A* i = p.get(); - p.reset(new B); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp deleted file mode 100644 index 5e98475..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp +++ /dev/null @@ -1,56 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test swap - -#include -#include - -#include "deleter_types.h" - -struct A -{ - int state_; - static int count; - A() : state_(0) {++count;} - explicit A(int i) : state_(i) {++count;} - A(const A& a) : state_(a.state_) {++count;} - A& operator=(const A& a) {state_ = a.state_; return *this;} - ~A() {--count;} - - friend bool operator==(const A& x, const A& y) - {return x.state_ == y.state_;} -}; - -int A::count = 0; - -int main() -{ - { - A* p1 = new A[3]; - std::unique_ptr > s1(p1, Deleter(1)); - A* p2 = new A[3]; - std::unique_ptr > s2(p2, Deleter(2)); - assert(s1.get() == p1); - assert(s1.get_deleter().state() == 1); - assert(s2.get() == p2); - assert(s2.get_deleter().state() == 2); - s1.swap(s2); - assert(s1.get() == p2); - assert(s1.get_deleter().state() == 2); - assert(s2.get() == p1); - assert(s2.get_deleter().state() == 1); - assert(A::count == 6); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp deleted file mode 100644 index 46ba139..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test op*() - -#include -#include - -int main() -{ - std::unique_ptr p(new int(3)); - assert(*p == 3); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp deleted file mode 100644 index 5989342..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test get_deleter() - -#include -#include -#include "test_macros.h" - -struct Deleter { - Deleter() {} - - void operator()(void*) const {} - - int test() { return 5; } - int test() const { return 6; } -}; - -int main() { - { - std::unique_ptr p; - assert(p.get_deleter().test() == 5); - } - { - const std::unique_ptr p; - assert(p.get_deleter().test() == 6); - } - { - typedef std::unique_ptr UPtr; - const Deleter d; - UPtr p(nullptr, d); - const UPtr& cp = p; - ASSERT_SAME_TYPE(decltype(p.get_deleter()), const Deleter&); - ASSERT_SAME_TYPE(decltype(cp.get_deleter()), const Deleter&); - assert(p.get_deleter().test() == 6); - assert(cp.get_deleter().test() == 6); - } - { - typedef std::unique_ptr UPtr; - Deleter d; - UPtr p(nullptr, d); - const UPtr& cp = p; - ASSERT_SAME_TYPE(decltype(p.get_deleter()), Deleter&); - ASSERT_SAME_TYPE(decltype(cp.get_deleter()), Deleter&); - assert(p.get_deleter().test() == 5); - assert(cp.get_deleter().test() == 5); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp deleted file mode 100644 index 519eae6..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test op[](size_t) - -#include -#include - -class A -{ - int state_; - static int next_; -public: - A() : state_(++next_) {} - int get() const {return state_;} - - friend bool operator==(const A& x, int y) - {return x.state_ == y;} - - A& operator=(int i) {state_ = i; return *this;} -}; - -int A::next_ = 0; - -int main() -{ - std::unique_ptr p(new A[3]); - assert(p[0] == 1); - assert(p[1] == 2); - assert(p[2] == 3); - p[0] = 3; - p[1] = 2; - p[2] = 1; - assert(p[0] == 3); - assert(p[1] == 2); - assert(p[2] == 1); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp deleted file mode 100644 index 380f2e1..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr::pointer type - -#include -#include - -#include "test_macros.h" - -struct Deleter -{ - struct pointer {}; -}; - -struct D2 { -private: - typedef void pointer; -}; - -struct D3 { - static long pointer; -}; - -int main() -{ - { - typedef std::unique_ptr P; - static_assert((std::is_same::value), ""); - } - { - typedef std::unique_ptr P; - static_assert((std::is_same::value), ""); - } -#if TEST_STD_VER >= 11 - { - typedef std::unique_ptr P; - static_assert(std::is_same::value, ""); - } - { - typedef std::unique_ptr P; - static_assert(std::is_same::value, ""); - } -#endif -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp deleted file mode 100644 index 87cfb72..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -#include - -#include "test_macros.h" - -// Can't copy from lvalue -int main() -{ - std::unique_ptr s, s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}} -#else - s2 = s; // expected-error {{'operator=' is a private member}} -#endif -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp deleted file mode 100644 index 67f4da2..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp +++ /dev/null @@ -1,75 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -// test move assignment. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr s1(new A); - A* p = s1.get(); - std::unique_ptr s2(new A); - assert(A::count == 2); - s2 = std::move(s1); - assert(A::count == 1); - assert(s2.get() == p); - assert(s1.get() == 0); - } - assert(A::count == 0); - { - std::unique_ptr > s1(new A, Deleter(5)); - A* p = s1.get(); - std::unique_ptr > s2(new A); - assert(A::count == 2); - s2 = std::move(s1); - assert(s2.get() == p); - assert(s1.get() == 0); - assert(A::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s1.get_deleter().state() == 0); - } - assert(A::count == 0); - { - CDeleter d1(5); - std::unique_ptr&> s1(new A, d1); - A* p = s1.get(); - CDeleter d2(6); - std::unique_ptr&> s2(new A, d2); - s2 = std::move(s1); - assert(s2.get() == p); - assert(s1.get() == 0); - assert(A::count == 1); - assert(d1.state() == 5); - assert(d2.state() == 5); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp deleted file mode 100644 index 9cea12b..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -#include - -#include "test_macros.h" - -// Can't copy from const lvalue - -int main() -{ - const std::unique_ptr s(new int); - std::unique_ptr s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}} -#else - // NOTE: The error says "constructor" because the assignment operator takes - // 's' by value and attempts to copy construct it. - s2 = s; // expected-error {{no matching constructor for initialization}} -#endif -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp deleted file mode 100644 index 05a057f..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -#include - -#include "test_macros.h" - -struct Deleter { - void operator()(int* p) {delete p;} -}; - -// Can't copy from lvalue -int main() -{ - std::unique_ptr s, s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}} -#else - s2 = s; // expected-error {{'operator=' is a private member}} -#endif -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp deleted file mode 100644 index 24703ec..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move assignment - -#include - -#include "test_macros.h" - -struct Deleter { - void operator()(int* p) {delete p;} -}; - -// Can't copy from a const lvalue -int main() -{ - const std::unique_ptr s(new int); - std::unique_ptr s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}} -#else - // NOTE: The error says "constructor" because the assignment operator takes - // 's' by value and attempts to copy construct it. - s2 = s; // expected-error {{no matching constructor for initialization}} -#endif -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp deleted file mode 100644 index 7876760..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp +++ /dev/null @@ -1,89 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - - -template -void testAssign(APtr& aptr, BPtr& bptr) { - A* p = bptr.get(); - assert(A::count == 2); - aptr = std::move(bptr); - assert(aptr.get() == p); - assert(bptr.get() == 0); - assert(A::count == 1); - assert(B::count == 1); -} - -template -void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) { - assert(lhs.get_deleter().state() == LHSState); - assert(rhs.get_deleter().state() == RHSState); -} - -int main() -{ - { - std::unique_ptr bptr(new B); - std::unique_ptr aptr(new A); - testAssign(aptr, bptr); - } - assert(A::count == 0); - assert(B::count == 0); - { - Deleter del(42); - std::unique_ptr > bptr(new B, std::move(del)); - std::unique_ptr > aptr(new A); - testAssign(aptr, bptr); - checkDeleter(aptr, bptr, 42, 0); - } - assert(A::count == 0); - assert(B::count == 0); - { - CDeleter adel(6); - CDeleter bdel(42); - std::unique_ptr&> bptr(new B, bdel); - std::unique_ptr&> aptr(new A, adel); - testAssign(aptr, bptr); - checkDeleter(aptr, bptr, 42, 42); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp deleted file mode 100644 index 816a598..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include - -#include "test_macros.h" - -struct A -{ - A() {} - virtual ~A() {} -}; - -struct B : public A -{ -}; - -// Can't assign from lvalue -int main() -{ - std::unique_ptr s; - std::unique_ptr s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{no viable overloaded '='}} -#else - // NOTE: The move-semantic emulation creates an ambiguous overload set - // so that assignment from an lvalue does not compile - s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}} -#endif -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp deleted file mode 100644 index 6e69d51..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include - -#include "test_macros.h" -#include "deleter_types.h" - -struct A -{ - A() {} - virtual ~A() {} -}; - -struct B : public A -{ -}; - -// Can't assign from lvalue -int main() -{ - std::unique_ptr > s; - std::unique_ptr > s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{no viable overloaded '='}} -#else - // NOTE: The move-semantic emulation creates an ambiguous overload set - // so that assignment from an lvalue does not compile - s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}} -#endif -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp deleted file mode 100644 index 1d89f99..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from lvalue - -#include - -#include "test_macros.h" -#include "deleter_types.h" - -struct A -{ - A() {} - virtual ~A() {} -}; - -struct B : public A -{ -}; - -// Can't assign from lvalue -int main() -{ - Deleter db; - std::unique_ptr& > s(new B, db); - Deleter da; - std::unique_ptr &> s2(new A, da); -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{no viable overloaded '='}} -#else - // NOTE: The move-semantic emulation creates an ambiguous overload set - // so that assignment from an lvalue does not compile - s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}} -#endif -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp deleted file mode 100644 index f7de69c..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include - -#include "test_macros.h" -#include "deleter_types.h" - -struct A -{ - A() {} - virtual ~A() {} -}; - -struct B : public A -{ -}; - -// Can't assign from lvalue -int main() -{ - const std::unique_ptr s(new B); - std::unique_ptr s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{no viable overloaded '='}} -#else - // NOTE: The error says "constructor" because the assignment operator takes - // 's' by value and attempts to copy construct it. - s2 = s; // expected-error {{no matching constructor for initialization}} -#endif -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp deleted file mode 100644 index 55ebe51..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from const lvalue - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const std::unique_ptr > s(new B); - A* p = s.get(); - std::unique_ptr > s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp deleted file mode 100644 index 657b011..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from const lvalue - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - Deleter db(5); - const std::unique_ptr&> s(new B, db); - A* p = s.get(); - Deleter da(6); - std::unique_ptr&> s2(new A, da); - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp deleted file mode 100644 index 4126484..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Do not convert from an array unique_ptr - -#include -#include -#include - -struct A -{ -}; - -struct Deleter -{ - void operator()(void*) {} -}; - -int main() -{ - std::unique_ptr s; - std::unique_ptr s2; - s2 = std::move(s); // expected-error {{no viable overloaded '='}} -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp deleted file mode 100644 index 1f317c7..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -#include -#include - -// template explicit unique_ptr(auto_ptr&); - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B -// : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - B* p = new B; - std::auto_ptr ap(p); - std::unique_ptr up(ap); - assert(up.get() == p); - assert(ap.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); - { - B* p = new B; - std::auto_ptr ap(p); - std::unique_ptr up; - up = ap; - assert(up.get() == p); - assert(ap.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp deleted file mode 100644 index 2dd5ea3..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -#include -#include - -// template explicit unique_ptr(auto_ptr&); - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -struct Deleter -{ - template - void operator()(T*) {} -}; - -int main() -{ - { - B* p = new B; - std::auto_ptr ap(p); - std::unique_ptr up(ap); - assert(up.get() == p); - assert(ap.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp deleted file mode 100644 index 7f58989..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp +++ /dev/null @@ -1,91 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -//============================================================================= -// TESTING std::unique_ptr::unique_ptr() -// -// Concerns: -// 1 The default constructor works for any default constructible deleter types. -// 2 The stored type 'T' is allowed to be incomplete. -// -// Plan -// 1 Default construct unique_ptr's with various deleter types (C-1) -// 2 Default construct a unique_ptr with an incomplete element_type and -// various deleter types (C-1,2) - -#include -#include -#include "test_macros.h" - -#include "deleter_types.h" - -#if defined(_LIBCPP_VERSION) && TEST_STD_VER >= 11 -_LIBCPP_SAFE_STATIC std::unique_ptr global_static_unique_ptr; -#endif - -struct IncompleteT; - -void checkNumIncompleteTypeAlive(int i); - -template > -struct StoresIncomplete { - std::unique_ptr m_ptr; - StoresIncomplete() {} - ~StoresIncomplete(); - - IncompleteT* get() const { return m_ptr.get(); } - Del& get_deleter() { return m_ptr.get_deleter(); } -}; - -int main() -{ - { - std::unique_ptr p; - assert(p.get() == 0); - } - { - std::unique_ptr > p; - assert(p.get() == 0); - assert(p.get_deleter().state() == 0); - p.get_deleter().set_state(5); - assert(p.get_deleter().state() == 5); - } - { - StoresIncomplete<> s; - assert(s.get() == 0); - checkNumIncompleteTypeAlive(0); - } - checkNumIncompleteTypeAlive(0); - { - StoresIncomplete< Deleter > s; - assert(s.get() == 0); - assert(s.get_deleter().state() == 0); - checkNumIncompleteTypeAlive(0); - } - checkNumIncompleteTypeAlive(0); -} - -struct IncompleteT { - static int count; - IncompleteT() { ++count; } - ~IncompleteT() {--count; } -}; - -int IncompleteT::count = 0; - -void checkNumIncompleteTypeAlive(int i) { - assert(IncompleteT::count == i); -} - -template -StoresIncomplete::~StoresIncomplete() { } diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp deleted file mode 100644 index 2ffe1be..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr default ctor - -#include - -// default unique_ptr ctor should require default Deleter ctor -class Deleter -{ - - Deleter() {} - -public: - - Deleter(Deleter&) {} - Deleter& operator=(Deleter&) {} - - void operator()(void*) const {} -}; - -int main() -{ - std::unique_ptr p; -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp deleted file mode 100644 index 6907501..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr default ctor - -#include - -// default unique_ptr ctor should require non-reference Deleter ctor -class Deleter -{ -public: - - void operator()(void*) {} -}; - -int main() -{ - std::unique_ptr p; -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp deleted file mode 100644 index 78f6e73..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr default ctor - -#include - -// default unique_ptr ctor should require non-pointer Deleter - -int main() -{ - std::unique_ptr p; -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp deleted file mode 100644 index f49702a..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp +++ /dev/null @@ -1,140 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -#include -#include -#include - -#include "deleter_types.h" - -//============================================================================= -// TESTING unique_ptr(unique_ptr&&) -// -// Concerns -// 1 The moved from pointer is empty and the new pointer stores the old value. -// 2 The only requirement on the deleter is that it is MoveConstructible -// or a reference. -// 3 The constructor works for explicitly moved values (ie std::move(x)) -// 4 The constructor works for true temporaries (ie a return value) -// -// Plan -// 1 Explicitly construct unique_ptr for various deleter types 'D'. -// check that the value and deleter have been properly moved. (C-1,2,3) -// -// 2 Use the expression 'sink(source())' to move construct a unique_ptr -// from a temporary. 'source' should return the unique_ptr by value and -// 'sink' should accept the unique_ptr by value. (C-1,2,4) - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -template -void sinkFunction(Expect) -{ -} - -typedef std::unique_ptr APtrSource1; -typedef std::unique_ptr > APtrSource2; -typedef std::unique_ptr& > APtrSource3; - -APtrSource1 source1() { - return APtrSource1 (new A); -} - -void sink1(APtrSource1 p) { - assert(p.get() != nullptr); -} - -APtrSource2 source2() { - return APtrSource2(new A, Deleter(5)); -} - -void sink2(APtrSource2 p) { - assert(p.get() != nullptr); - assert(p.get_deleter().state() == 5); -} - -APtrSource3 source3() { - static NCDeleter d(5); - return APtrSource3(new A, d); -} - -void sink3(APtrSource3 p) { - assert(p.get() != nullptr); - assert(p.get_deleter().state() == 5); - assert(&p.get_deleter() == &source3().get_deleter()); -} - -int main() -{ - { - typedef std::unique_ptr APtr; - APtr s(new A); - A* p = s.get(); - APtr s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); - { - typedef Deleter MoveDel; - typedef std::unique_ptr APtr; - MoveDel d(5); - APtr s(new A, std::move(d)); - assert(d.state() == 0); - assert(s.get_deleter().state() == 5); - A* p = s.get(); - APtr s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - { - typedef NCDeleter NonCopyDel; - typedef std::unique_ptr APtr; - - NonCopyDel d; - APtr s(new A, d); - A* p = s.get(); - APtr s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - { - sink1(source1()); - assert(A::count == 0); - sink2(source2()); - assert(A::count == 0); - sink3(source3()); - assert(A::count == 0); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp deleted file mode 100644 index 68ad589b..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -#include -#include - -// test move ctor. Can't copy from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr s(new A); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp deleted file mode 100644 index 897b889..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -#include -#include - -// test move ctor. Can't copy from const lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - const std::unique_ptr s(new A); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp deleted file mode 100644 index 7fb1a0a..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -#include -#include - -// test move ctor. Can't copy from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete p;} -}; - -int main() -{ - { - std::unique_ptr s(new A); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp deleted file mode 100644 index 671e343..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr move ctor - -#include -#include - -// test move ctor. Can't copy from const lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete p;} -}; - -int main() -{ - { - const std::unique_ptr s(new A); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp deleted file mode 100644 index ada0109..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp +++ /dev/null @@ -1,171 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// - -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// NOTE: unique_ptr does not provide converting constructors in c++03 -// XFAIL: c++98, c++03 - - - -#include -#include -#include -#include - -#include "deleter_types.h" - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - - -template -void checkReferenceDeleter(LHS& lhs, RHS& rhs) { - typedef typename LHS::deleter_type NewDel; - static_assert(std::is_reference::value, ""); - rhs.get_deleter().set_state(42); - assert(rhs.get_deleter().state() == 42); - assert(lhs.get_deleter().state() == 42); - lhs.get_deleter().set_state(99); - assert(lhs.get_deleter().state() == 99); - assert(rhs.get_deleter().state() == 99); -} - -template -void checkDeleter(LHS& lhs, RHS& rhs, int LHSVal, int RHSVal) { - assert(lhs.get_deleter().state() == LHSVal); - assert(rhs.get_deleter().state() == RHSVal); -} - -template -void checkCtor(LHS& lhs, RHS& rhs, A* RHSVal) { - assert(lhs.get() == RHSVal); - assert(rhs.get() == nullptr); - assert(A::count == 1); - assert(B::count == 1); -} - -void checkNoneAlive() { - assert(A::count == 0); - assert(B::count == 0); -} - -int main() -{ - { - typedef std::unique_ptr APtr; - typedef std::unique_ptr BPtr; - { // explicit - BPtr b(new B); - A* p = b.get(); - APtr a(std::move(b)); - checkCtor(a, b, p); - } - checkNoneAlive(); - { // implicit - BPtr b(new B); - A* p = b.get(); - APtr a = std::move(b); - checkCtor(a, b, p); - } - checkNoneAlive(); - } - { // test with moveable deleters - typedef std::unique_ptr > APtr; - typedef std::unique_ptr > BPtr; - { - Deleter del(5); - BPtr b(new B, std::move(del)); - A* p = b.get(); - APtr a(std::move(b)); - checkCtor(a, b, p); - checkDeleter(a, b, 5, 0); - } - checkNoneAlive(); - { - Deleter del(5); - BPtr b(new B, std::move(del)); - A* p = b.get(); - APtr a = std::move(b); - checkCtor(a, b, p); - checkDeleter(a, b, 5, 0); - } - checkNoneAlive(); - - } - { // test with reference deleters - typedef std::unique_ptr& > APtr; - typedef std::unique_ptr& > BPtr; - NCDeleter del(5); - { - BPtr b(new B, del); - A* p = b.get(); - APtr a(std::move(b)); - checkCtor(a, b, p); - checkReferenceDeleter(a, b); - } - checkNoneAlive(); - { - BPtr b(new B, del); - A* p = b.get(); - APtr a = std::move(b); - checkCtor(a, b, p); - checkReferenceDeleter(a, b); - } - checkNoneAlive(); - } - { - typedef std::unique_ptr > APtr; - typedef std::unique_ptr& > BPtr; - CDeleter del(5); - { - BPtr b(new B, del); - A* p = b.get(); - APtr a(std::move(b)); - checkCtor(a, b, p); - checkDeleter(a, b, 5, 5); - } - checkNoneAlive(); - { - BPtr b(new B, del); - A* p = b.get(); - APtr a = std::move(b); - checkCtor(a, b, p); - checkDeleter(a, b, 5, 5); - } - checkNoneAlive(); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp deleted file mode 100644 index ed1fe8c..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp +++ /dev/null @@ -1,56 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -// Can't construct from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp deleted file mode 100644 index 3d1cb6f..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr > s(new B); - A* p = s.get(); - std::unique_ptr > s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp deleted file mode 100644 index 7409199..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter d; - std::unique_ptr&> s(new B, d); - A* p = s.get(); - std::unique_ptr&> s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp deleted file mode 100644 index 981ea70..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// implicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp deleted file mode 100644 index 76462dc..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp +++ /dev/null @@ -1,51 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -#include "deleter_types.h" - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Implicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - std::unique_ptr > s(new B); - std::unique_ptr > s2 = s; -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp deleted file mode 100644 index 5b9b12e..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter d; - std::unique_ptr&> s(new B, d); - A* p = s.get(); - std::unique_ptr&> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp deleted file mode 100644 index bef022c..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp deleted file mode 100644 index 016eadc..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp +++ /dev/null @@ -1,86 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class Deleter -{ - int state_; - Deleter(const Deleter&); - Deleter& operator=(const Deleter&); - -public: - Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} - Deleter& operator=(Deleter&& r) - { - state_ = r.state_; - r.state_ = 0; - return *this; - } - - Deleter() : state_(5) {} - - template - Deleter(Deleter&& d, - typename std::enable_if::value>::type* = 0) - : state_(d.state()) {d.set_state(0);} - -private: - template - Deleter(const Deleter& d, - typename std::enable_if::value>::type* = 0); - -public: - int state() const {return state_;} - void set_state(int i) {state_ = i;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - const std::unique_ptr > s; - std::unique_ptr > s2(s); // expected-error {{no matching constructor}} -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp deleted file mode 100644 index a475c17..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter d; - const std::unique_ptr&> s(new B, d); - A* p = s.get(); - std::unique_ptr&> s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp deleted file mode 100644 index f0da5ef..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// implicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const std::unique_ptr s(new B); - A* p = s.get(); - std::unique_ptr s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp deleted file mode 100644 index 1b8bb73..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp +++ /dev/null @@ -1,86 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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 - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Implicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class Deleter -{ - int state_; - - Deleter(const Deleter&); - Deleter& operator=(const Deleter&); -public: - Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} - Deleter& operator=(Deleter&& r) - { - state_ = r.state_; - r.state_ = 0; - return *this; - } - - Deleter() : state_(5) {} - - template - Deleter(Deleter&& d, - typename std::enable_if::value>::type* = 0) - : state_(d.state()) {d.set_state(0);} - -private: - template - Deleter(const Deleter& d, - typename std::enable_if::value>::type* = 0); - -public: - int state() const {return state_;} - void set_state(int i) {state_ = i;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - const std::unique_ptr > s; - std::unique_ptr > s2 = s; // expected-error {{no viable conversion}} -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp deleted file mode 100644 index 095bec6..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include -#include -#include - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter d; - const std::unique_ptr&> s(new B, d); - A* p = s.get(); - std::unique_ptr&> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp deleted file mode 100644 index a4bd2cb..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr converting move ctor - -// Do not convert from an array unique_ptr - -#include -#include -#include - -struct A -{ -}; - -struct Deleter -{ - void operator()(void*) {} -}; - -int main() -{ - std::unique_ptr s; - std::unique_ptr s2(std::move(s)); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp deleted file mode 100644 index 67a48a3..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// unique_ptr(nullptr_t); - -#include -#include - -// default unique_ptr ctor should only require default Deleter ctor -class Deleter -{ - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(void*) {} -}; - -int main() -{ - { - std::unique_ptr p(nullptr); - assert(p.get() == 0); - } - { - std::unique_ptr p(nullptr); - assert(p.get() == 0); - assert(p.get_deleter().state() == 5); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp deleted file mode 100644 index da502b0..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp +++ /dev/null @@ -1,163 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -//============================================================================= -// TESTING std::unique_ptr::unique_ptr() -// -// Concerns: -// 1 The pointer constructor works for any default constructible deleter types. -// 2 The pointer constructor accepts pointers to derived types. -// 2 The stored type 'T' is allowed to be incomplete. -// -// Plan -// 1 Construct unique_ptr's with a pointer to 'T' and various deleter -// types (C-1) -// 2 Construct unique_ptr's with a pointer to 'D' and various deleter -// types where 'D' is derived from 'T'. (C-1,2) -// 3 Construct a unique_ptr with a pointer to 'T' and various deleter -// types where 'T' is an incomplete type (C-1,3) - -// Test unique_ptr(pointer) ctor - -#include -#include - -#include "deleter_types.h" - -// unique_ptr(pointer) ctor should only require default Deleter ctor - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - - -struct IncompleteT; - -IncompleteT* getIncomplete(); -void checkNumIncompleteTypeAlive(int i); - -template > -struct StoresIncomplete { - std::unique_ptr m_ptr; - StoresIncomplete() {} - explicit StoresIncomplete(IncompleteT* ptr) : m_ptr(ptr) {} - ~StoresIncomplete(); - - IncompleteT* get() const { return m_ptr.get(); } - Del& get_deleter() { return m_ptr.get_deleter(); } -}; - -void test_pointer() -{ - { - A* p = new A; - assert(A::count == 1); - std::unique_ptr s(p); - assert(s.get() == p); - } - assert(A::count == 0); - { - A* p = new A; - assert(A::count == 1); - std::unique_ptr > s(p); - assert(s.get() == p); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); -} - -void test_derived() -{ - { - B* p = new B; - assert(A::count == 1); - assert(B::count == 1); - std::unique_ptr s(p); - assert(s.get() == p); - } - assert(A::count == 0); - assert(B::count == 0); - { - B* p = new B; - assert(A::count == 1); - assert(B::count == 1); - std::unique_ptr > s(p); - assert(s.get() == p); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} - -void test_incomplete() -{ - { - IncompleteT* p = getIncomplete(); - checkNumIncompleteTypeAlive(1); - StoresIncomplete<> s(p); - assert(s.get() == p); - } - checkNumIncompleteTypeAlive(0); - { - IncompleteT* p = getIncomplete(); - checkNumIncompleteTypeAlive(1); - StoresIncomplete< NCDeleter > s(p); - assert(s.get() == p); - assert(s.get_deleter().state() == 0); - } - checkNumIncompleteTypeAlive(0); -} - -struct IncompleteT { - static int count; - IncompleteT() { ++count; } - ~IncompleteT() {--count; } -}; - -int IncompleteT::count = 0; - -IncompleteT* getIncomplete() { - return new IncompleteT; -} - -void checkNumIncompleteTypeAlive(int i) { - assert(IncompleteT::count == i); -} - -template -StoresIncomplete::~StoresIncomplete() { } - -int main() -{ - test_pointer(); - test_derived(); - test_incomplete(); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp deleted file mode 100644 index 1af04b2..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -#include - -// unique_ptr(pointer) ctor should require default Deleter ctor -class Deleter -{ - - Deleter() {} - -public: - - Deleter(Deleter&) {} - Deleter& operator=(Deleter&) {} - - void operator()(void*) const {} -}; - -int main() -{ - std::unique_ptr p(new int); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp deleted file mode 100644 index 9b7dd8c..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -#include - -// unique_ptr(pointer) ctor should require non-reference Deleter ctor -class Deleter -{ -public: - - void operator()(void*) {} -}; - -int main() -{ - std::unique_ptr p(new int); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp deleted file mode 100644 index a917d87..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -#include - -// unique_ptr(pointer) ctor should require non-pointer Deleter - -int main() -{ - std::unique_ptr p(new int); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp deleted file mode 100644 index 9294681..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp +++ /dev/null @@ -1,123 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -//============================================================================= -// TESTING unique_ptr(pointer, deleter) -// -// Concerns: -// 1 unique_ptr(pointer, deleter&&) only requires a MoveConstructible deleter. -// 2 unique_ptr(pointer, deleter&) requires a CopyConstructible deleter. -// 3 unique_ptr(pointer, deleter) does not require a CopyConstructible deleter. -// 4 unique_ptr(pointer, deleter) does not require a CopyConstructible deleter. -// 5 unique_ptr(pointer, deleter) should work for derived pointers. -// 6 unique_ptr(pointer, deleter) should work with function pointers. -// 7 unique_ptr should work. - - -#include -#include - -#include "deleter_types.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -bool my_free_called = false; - -void my_free(void*) { - my_free_called = true; -} - -int main() -{ - { // MoveConstructible deleter (C-1) - A* p = new A; - assert(A::count == 1); - std::unique_ptr > s(p, Deleter(5)); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); - { // CopyConstructible deleter (C-2) - A* p = new A; - assert(A::count == 1); - CopyDeleter d(5); - std::unique_ptr > s(p, d); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - d.set_state(6); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); - { // Reference deleter (C-3) - A* p = new A; - assert(A::count == 1); - NCDeleter d(5); - std::unique_ptr&> s(p, d); - assert(s.get() == p); - assert(&s.get_deleter() == &d); - assert(s.get_deleter().state() == 5); - d.set_state(6); - assert(s.get_deleter().state() == 6); - } - assert(A::count == 0); - { // Const Reference deleter (C-4) - A* p = new A; - assert(A::count == 1); - NCConstDeleter d(5); - std::unique_ptr const&> s(p, d); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - assert(&s.get_deleter() == &d); - } - assert(A::count == 0); - { // Derived pointers (C-5) - B* p = new B; - assert(A::count == 1); - assert(B::count == 1); - std::unique_ptr > s(p, Deleter(5)); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); - assert(B::count == 0); - { // Void and function pointers (C-6,7) - { - int i = 0; - std::unique_ptr s(&i, my_free); - assert(s.get() == &i); - assert(s.get_deleter() == my_free); - assert(!my_free_called); - } - assert(my_free_called); - } -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp deleted file mode 100644 index dadd4ec..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp +++ /dev/null @@ -1,27 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test release - -#include -#include - -int main() -{ - std::unique_ptr p(new int(3)); - int* i = p.get(); - int* j = p.release(); - assert(p.get() == 0); - assert(i == j); - delete j; -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp deleted file mode 100644 index 2cf7f8b..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp +++ /dev/null @@ -1,50 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test reset - -#include -#include - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr p(new A); - assert(A::count == 1); - A* i = p.get(); - assert(i != nullptr); - p.reset(); - assert(A::count == 0); - assert(p.get() == 0); - } - assert(A::count == 0); - { - std::unique_ptr p(new A); - assert(A::count == 1); - A* i = p.get(); - assert(i != nullptr); - p.reset(new A); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp deleted file mode 100644 index 68a3204..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test swap - -#include -#include - -#include "deleter_types.h" - -struct A -{ - int state_; - static int count; - explicit A(int i) : state_(i) {++count;} - A(const A& a) : state_(a.state_) {++count;} - A& operator=(const A& a) {state_ = a.state_; return *this;} - ~A() {--count;} - - friend bool operator==(const A& x, const A& y) - {return x.state_ == y.state_;} -}; - -int A::count = 0; - -int main() -{ - { - A* p1 = new A(1); - std::unique_ptr > s1(p1, Deleter(1)); - A* p2 = new A(2); - std::unique_ptr > s2(p2, Deleter(2)); - assert(s1.get() == p1); - assert(*s1 == A(1)); - assert(s1.get_deleter().state() == 1); - assert(s2.get() == p2); - assert(*s2 == A(2)); - assert(s2.get_deleter().state() == 2); - s1.swap(s2); - assert(s1.get() == p2); - assert(*s1 == A(2)); - assert(s1.get_deleter().state() == 2); - assert(s2.get() == p1); - assert(*s2 == A(1)); - assert(s2.get_deleter().state() == 1); - assert(A::count == 2); - } - assert(A::count == 0); -} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp b/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp deleted file mode 100644 index 24fa6be..0000000 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp +++ /dev/null @@ -1,24 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// 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. -// -//===----------------------------------------------------------------------===// - -// - -// unique_ptr - -// test get - -#include -#include - -int main() -{ - int* p = new int; - std::unique_ptr s(p); - assert(s.get() == p); -} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/README.TXT b/libcxx/test/std/utilities/smartptr/unique.ptr/README.TXT new file mode 100644 index 0000000..20f77f6 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/README.TXT @@ -0,0 +1,16 @@ +Test Naming and Directory Structure +=================================== + +The directory structure for the unique_ptr class templates differs from the +normal test directory naming conventions (e.g. matching the stable name in the standard). + +Instead of having a [unique.ptr.single] and [unique.ptr.runtime] directory, +each containing their own tests, a single directory, "unique.ptr.class", +contains both sets of tests. + +This allows the common behavior of the two unique_ptr specializations to be +tested in the same place without duplication. + +Tests specific to [unique.ptr.single] have the suffix ".single.pass.cpp" +and those specific to [unique.ptr.runtime] are named "*.runtime.pass.cpp". +Tests for both specializations are named normally. diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/nothing_to_do.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/nothing_to_do.pass.cpp diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/pointer_type.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/pointer_type.pass.cpp new file mode 100644 index 0000000..54c2cf1 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/pointer_type.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// Test unique_ptr::pointer type + +#include +#include + +#include "test_macros.h" + +struct Deleter { + struct pointer {}; +}; + +struct D2 { +private: + typedef void pointer; +}; + +struct D3 { + static long pointer; +}; + +template +void test_basic() { + typedef typename std::conditional::type VT; + { + typedef std::unique_ptr P; + static_assert((std::is_same::value), ""); + } + { + typedef std::unique_ptr P; + static_assert((std::is_same::value), + ""); + } +#if TEST_STD_VER >= 11 + { + typedef std::unique_ptr P; + static_assert(std::is_same::value, ""); + } + { + typedef std::unique_ptr P; + static_assert(std::is_same::value, ""); + } +#endif +} + +int main() { + test_basic(); + test_basic(); +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move.pass.cpp new file mode 100644 index 0000000..3784218 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move.pass.cpp @@ -0,0 +1,119 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// unique_ptr + +// Test unique_ptr move assignment + +// test move assignment. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +#include +#include +#include + +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +struct GenericDeleter { + void operator()(void*) const; +}; + +template +void test_basic() { + typedef typename std::conditional::type VT; + const int expect_alive = IsArray ? 5 : 1; + { + std::unique_ptr s1(newValue(expect_alive)); + A* p = s1.get(); + std::unique_ptr s2(newValue(expect_alive)); + assert(A::count == (expect_alive * 2)); + s2 = std::move(s1); + assert(A::count == expect_alive); + assert(s2.get() == p); + assert(s1.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr > s1(newValue(expect_alive), + Deleter(5)); + A* p = s1.get(); + std::unique_ptr > s2(newValue(expect_alive)); + assert(A::count == (expect_alive * 2)); + s2 = std::move(s1); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(A::count == expect_alive); + assert(s2.get_deleter().state() == 5); + assert(s1.get_deleter().state() == 0); + } + assert(A::count == 0); + { + CDeleter d1(5); + std::unique_ptr&> s1(newValue(expect_alive), d1); + A* p = s1.get(); + CDeleter d2(6); + std::unique_ptr&> s2(newValue(expect_alive), d2); + s2 = std::move(s1); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(A::count == expect_alive); + assert(d1.state() == 5); + assert(d2.state() == 5); + } + assert(A::count == 0); +} + +template +void test_sfinae() { + typedef typename std::conditional::type VT; + { + typedef std::unique_ptr U; + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(std::is_assignable::value, ""); + } + { + typedef std::unique_ptr U; + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(std::is_assignable::value, ""); + } + { + typedef std::unique_ptr&> U; + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(std::is_assignable::value, ""); + } + { + typedef std::unique_ptr&> U; + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(std::is_assignable::value, ""); + } +} + +int main() { + { + test_basic(); + test_sfinae(); + } + { + test_basic(); + test_sfinae(); + } +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.runtime.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.runtime.pass.cpp new file mode 100644 index 0000000..9b946a7 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.runtime.pass.cpp @@ -0,0 +1,124 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include +#include +#include + +#include "unique_ptr_test_helper.h" + +template +void testAssign(APtr& aptr, BPtr& bptr) { + A* p = bptr.get(); + assert(A::count == 2); + aptr = std::move(bptr); + assert(aptr.get() == p); + assert(bptr.get() == 0); + assert(A::count == 1); + assert(B::count == 1); +} + +template +void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) { + assert(lhs.get_deleter().state() == LHSState); + assert(rhs.get_deleter().state() == RHSState); +} + +template +struct NCConvertingDeleter { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template + NCConvertingDeleter(NCConvertingDeleter&&) {} + + void operator()(T*) const {} +}; + +template +struct NCConvertingDeleter { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template + NCConvertingDeleter(NCConvertingDeleter&&) {} + + void operator()(T*) const {} +}; + +struct GenericDeleter { + void operator()(void*) const; +}; + +struct NCGenericDeleter { + NCGenericDeleter() = default; + NCGenericDeleter(NCGenericDeleter const&) = delete; + NCGenericDeleter(NCGenericDeleter&&) = default; + + void operator()(void*) const {} +}; + +void test_sfinae() { + using DA = NCConvertingDeleter; // non-copyable deleters + using DAC = NCConvertingDeleter; // non-copyable deleters + + using DB = NCConvertingDeleter; + using UA = std::unique_ptr; + using UAC = std::unique_ptr; + using UB = std::unique_ptr; + using UAD = std::unique_ptr; + using UACD = std::unique_ptr; + + using UBD = std::unique_ptr; + { // cannot move from an lvalue + static_assert(std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + } + { // cannot move if the deleter-types cannot convert + static_assert(std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr; + using UA2 = std::unique_ptr; + static_assert(!std::is_assignable::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr; + using UA2 = std::unique_ptr; + static_assert(!std::is_assignable::value, ""); + } + { // cannot move-convert from unique_ptr + using UA1 = std::unique_ptr; + using UA2 = std::unique_ptr; + static_assert(!std::is_assignable::value, ""); + } + { // cannot move-convert from unique_ptr + using UA1 = std::unique_ptr; + using UA2 = std::unique_ptr; + static_assert(!std::is_assignable::value, ""); + } +} + +int main() { + test_sfinae(); + // FIXME: add tests +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.single.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.single.pass.cpp new file mode 100644 index 0000000..3f2ea42 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.single.pass.cpp @@ -0,0 +1,145 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include +#include +#include + +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +template +void testAssign(APtr& aptr, BPtr& bptr) { + A* p = bptr.get(); + assert(A::count == 2); + aptr = std::move(bptr); + assert(aptr.get() == p); + assert(bptr.get() == 0); + assert(A::count == 1); + assert(B::count == 1); +} + +template +void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) { + assert(lhs.get_deleter().state() == LHSState); + assert(rhs.get_deleter().state() == RHSState); +} + +template +struct NCConvertingDeleter { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template + NCConvertingDeleter(NCConvertingDeleter&&) {} + + void operator()(T*) const {} +}; + +template +struct NCConvertingDeleter { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template + NCConvertingDeleter(NCConvertingDeleter&&) {} + + void operator()(T*) const {} +}; + +struct NCGenericDeleter { + NCGenericDeleter() = default; + NCGenericDeleter(NCGenericDeleter const&) = delete; + NCGenericDeleter(NCGenericDeleter&&) = default; + + void operator()(void*) const {} +}; + +void test_sfinae() { + using DA = NCConvertingDeleter; // non-copyable deleters + using DB = NCConvertingDeleter; + using UA = std::unique_ptr; + using UB = std::unique_ptr; + using UAD = std::unique_ptr; + using UBD = std::unique_ptr; + { // cannot move from an lvalue + static_assert(std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + } + { // cannot move if the deleter-types cannot convert + static_assert(std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr; + using UB1 = std::unique_ptr; + static_assert(!std::is_assignable::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr; + using UB1 = std::unique_ptr; + static_assert(!std::is_assignable::value, ""); + } + { // cannot move-convert from unique_ptr + using UA1 = std::unique_ptr; + using UA2 = std::unique_ptr; + using UB1 = std::unique_ptr; + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + } + { // cannot move-convert from unique_ptr + using UA1 = std::unique_ptr; + using UA2 = std::unique_ptr; + using UB1 = std::unique_ptr; + static_assert(!std::is_assignable::value, ""); + static_assert(!std::is_assignable::value, ""); + } +} + +int main() { + test_sfinae(); + { + std::unique_ptr bptr(new B); + std::unique_ptr aptr(new A); + testAssign(aptr, bptr); + } + assert(A::count == 0); + assert(B::count == 0); + { + Deleter del(42); + std::unique_ptr > bptr(new B, std::move(del)); + std::unique_ptr > aptr(new A); + testAssign(aptr, bptr); + checkDeleter(aptr, bptr, 42, 0); + } + assert(A::count == 0); + assert(B::count == 0); + { + CDeleter adel(6); + CDeleter bdel(42); + std::unique_ptr&> bptr(new B, bdel); + std::unique_ptr&> aptr(new A, adel); + testAssign(aptr, bptr); + checkDeleter(aptr, bptr, 42, 42); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/null.pass.cpp similarity index 57% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/null.pass.cpp index e2d7956..165d48a 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/null.pass.cpp @@ -16,26 +16,24 @@ #include #include -// test assignment from null - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; +#include "unique_ptr_test_helper.h" -int A::count = 0; - -int main() -{ - { - std::unique_ptr s2(new A); - assert(A::count == 1); - s2 = 0; +// test assignment from null +template +void test_basic() { + typedef typename std::conditional::type VT; + const int expect_alive = IsArray ? 5 : 1; + { + std::unique_ptr s2(newValue(expect_alive)); + assert(A::count == expect_alive); + s2 = NULL; assert(A::count == 0); assert(s2.get() == 0); - } - assert(A::count == 0); + } + assert(A::count == 0); +} + +int main() { + test_basic(); + test_basic(); } diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/nullptr.pass.cpp similarity index 59% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/nullptr.pass.cpp index fb15849..e1e2e32 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/nullptr.pass.cpp @@ -16,26 +16,25 @@ #include #include +#include "unique_ptr_test_helper.h" + // test assignment from null -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr s2(new A); - assert(A::count == 1); +template +void test_basic() { + typedef typename std::conditional::type VT; + const int expect_alive = IsArray ? 5 : 1; + { + std::unique_ptr s2(newValue(expect_alive)); + assert(A::count == expect_alive); s2 = nullptr; assert(A::count == 0); assert(s2.get() == 0); - } - assert(A::count == 0); + } + assert(A::count == 0); +} + +int main() { + test_basic(); + test_basic(); } diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/auto_pointer.pass.cpp similarity index 50% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/auto_pointer.pass.cpp index f878ce4..7d5e9bc 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/auto_pointer.pass.cpp @@ -23,30 +23,47 @@ #include "test_macros.h" -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} +struct A { + static int count; + A() { ++count; } + A(const A&) { ++count; } + virtual ~A() { --count; } }; int A::count = 0; -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} +struct B : public A { + static int count; + B() { ++count; } + B(const B&) { ++count; } + virtual ~B() { --count; } }; int B::count = 0; -int main() -{ - { +struct C {}; + +struct Deleter { + void operator()(void*) {} +}; + +void test_sfinae() { + { + // the auto_ptr constructor should be disable with a non-default deleter. + using AP = std::auto_ptr; + using U = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + } + { + // the auto_ptr constructor should be disabled when the pointer types are incompatible. + using AP = std::auto_ptr; + using U = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + } +} + +int main() { + { B* p = new B; std::auto_ptr ap(p); std::unique_ptr up(std::move(ap)); @@ -54,10 +71,10 @@ int main() assert(ap.get() == 0); assert(A::count == 1); assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); - { + } + assert(A::count == 0); + assert(B::count == 0); + { B* p = new B; std::auto_ptr ap(p); std::unique_ptr up; @@ -66,15 +83,15 @@ int main() assert(ap.get() == 0); assert(A::count == 1); assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); + } + assert(A::count == 0); + assert(B::count == 0); #if TEST_STD_VER >= 11 - { - static_assert(std::is_nothrow_constructible< - std::unique_ptr, - std::auto_ptr&& - >::value, ""); - } + { + static_assert(std::is_nothrow_constructible, + std::auto_ptr&&>::value, + ""); + } #endif + test_sfinae(); } diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp new file mode 100644 index 0000000..03bd6c5 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +//============================================================================= +// TESTING std::unique_ptr::unique_ptr() +// +// Concerns: +// 1 The default constructor works for any default constructible deleter types. +// 2 The stored type 'T' is allowed to be incomplete. +// +// Plan +// 1 Default construct unique_ptr's with various deleter types (C-1) +// 2 Default construct a unique_ptr with an incomplete element_type and +// various deleter types (C-1,2) + +#include +#include +#include "test_macros.h" + +#include "test_macros.h" +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +#include "test_workarounds.h" // For TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES + +#if defined(_LIBCPP_VERSION) && TEST_STD_VER >= 11 +_LIBCPP_SAFE_STATIC std::unique_ptr global_static_unique_ptr_single; +_LIBCPP_SAFE_STATIC std::unique_ptr global_static_unique_ptr_runtime; +#endif + +#if TEST_STD_VER >= 11 +struct NonDefaultDeleter { + NonDefaultDeleter() = delete; + void operator()(void*) const {} +}; +#endif + +template +void test_sfinae() { +#if TEST_STD_VER >= 11 && !defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES) + { // the constructor does not participate in overload resultion when + // the deleter is a pointer type + using U = std::unique_ptr; + static_assert(!std::is_default_constructible::value, ""); + } + { // the constructor does not participate in overload resolution when + // the deleter is not default constructible + using Del = CDeleter; + using U1 = std::unique_ptr; + using U2 = std::unique_ptr; + using U3 = std::unique_ptr; + static_assert(!std::is_default_constructible::value, ""); + static_assert(!std::is_default_constructible::value, ""); + static_assert(!std::is_default_constructible::value, ""); + } +#endif +} + +template +void test_basic() { +#if TEST_STD_VER >= 11 + { + using U1 = std::unique_ptr; + using U2 = std::unique_ptr >; + static_assert(std::is_nothrow_default_constructible::value, ""); + static_assert(std::is_nothrow_default_constructible::value, ""); + } +#endif + { + std::unique_ptr p; + assert(p.get() == 0); + } + { + std::unique_ptr > p; + assert(p.get() == 0); + assert(p.get_deleter().state() == 0); + p.get_deleter().set_state(5); + assert(p.get_deleter().state() == 5); + } +} + +DEFINE_AND_RUN_IS_INCOMPLETE_TEST({ + doIncompleteTypeTest(0); + doIncompleteTypeTest >(0); +} { + doIncompleteTypeTest(0); + doIncompleteTypeTest >(0); +}) + +int main() { + { + test_sfinae(); + test_basic(); + } + { + test_sfinae(); + test_basic(); + } +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move.pass.cpp new file mode 100644 index 0000000..8f52fe5 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move.pass.cpp @@ -0,0 +1,151 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// Test unique_ptr move ctor + +#include +#include +#include + +#include "test_macros.h" +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +//============================================================================= +// TESTING unique_ptr(unique_ptr&&) +// +// Concerns +// 1 The moved from pointer is empty and the new pointer stores the old value. +// 2 The only requirement on the deleter is that it is MoveConstructible +// or a reference. +// 3 The constructor works for explicitly moved values (ie std::move(x)) +// 4 The constructor works for true temporaries (ie a return value) +// +// Plan +// 1 Explicitly construct unique_ptr for various deleter types 'D'. +// check that the value and deleter have been properly moved. (C-1,2,3) +// +// 2 Use the expression 'sink(source())' to move construct a unique_ptr +// from a temporary. 'source' should return the unique_ptr by value and +// 'sink' should accept the unique_ptr by value. (C-1,2,4) + +template +std::unique_ptr source1() { + return std::unique_ptr(newValue(1)); +} + +template +std::unique_ptr > source2() { + return std::unique_ptr >(newValue(1), Deleter(5)); +} + +template +std::unique_ptr&> source3() { + static NCDeleter d(5); + return std::unique_ptr&>(newValue(1), d); +} + +template +void sink1(std::unique_ptr p) { + assert(p.get() != nullptr); +} + +template +void sink2(std::unique_ptr > p) { + assert(p.get() != nullptr); + assert(p.get_deleter().state() == 5); +} + +template +void sink3(std::unique_ptr&> p) { + assert(p.get() != nullptr); + assert(p.get_deleter().state() == 5); + assert(&p.get_deleter() == &source3().get_deleter()); +} + +template +void test_sfinae() { + typedef std::unique_ptr U; + { // Ensure unique_ptr is non-copyable + static_assert((!std::is_constructible::value), ""); + static_assert((!std::is_constructible::value), ""); + } +} + +template +void test_basic() { + typedef typename std::conditional::type VT; + const int expect_alive = IsArray ? 5 : 1; + { + typedef std::unique_ptr APtr; + APtr s(newValue(expect_alive)); + A* p = s.get(); + APtr s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == expect_alive); + } + assert(A::count == 0); + { + typedef Deleter MoveDel; + typedef std::unique_ptr APtr; + MoveDel d(5); + APtr s(newValue(expect_alive), std::move(d)); + assert(d.state() == 0); + assert(s.get_deleter().state() == 5); + A* p = s.get(); + APtr s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == expect_alive); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + { + typedef NCDeleter NonCopyDel; + typedef std::unique_ptr APtr; + + NonCopyDel d; + APtr s(newValue(expect_alive), d); + A* p = s.get(); + APtr s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == expect_alive); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + { + sink1(source1()); + assert(A::count == 0); + sink2(source2()); + assert(A::count == 0); + sink3(source3()); + assert(A::count == 0); + } + assert(A::count == 0); +} + +int main() { + { + test_basic(); + test_sfinae(); + } + { + test_basic(); + test_sfinae(); + } +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.runtime.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.runtime.pass.cpp new file mode 100644 index 0000000..b259049 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.runtime.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include +#include + +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +template +struct GenericDeleter { + void operator()(void*) const {} +}; + +template +struct GenericConvertingDeleter { + template + GenericConvertingDeleter(GenericConvertingDeleter) {} + void operator()(void*) const {} +}; + +void test_sfinae() { + { // Disallow copying + using U1 = std::unique_ptr >; + using U2 = std::unique_ptr >; + static_assert(std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } + { // Disallow illegal qualified conversions + using U1 = std::unique_ptr; + using U2 = std::unique_ptr; + static_assert(std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } + { // Disallow base-to-derived conversions. + using UA = std::unique_ptr; + using UB = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + } + { // Disallow base-to-derived conversions. + using UA = std::unique_ptr >; + using UB = std::unique_ptr >; + static_assert(!std::is_constructible::value, ""); + } + { // Disallow invalid deleter initialization + using U1 = std::unique_ptr >; + using U2 = std::unique_ptr >; + static_assert(!std::is_constructible::value, ""); + } + { // Disallow reference deleters with different qualifiers + using U1 = std::unique_ptr&>; + using U2 = std::unique_ptr&>; + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } + { + using U1 = std::unique_ptr; + using U2 = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } +} + +int main() { test_sfinae(); } diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.single.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.single.pass.cpp new file mode 100644 index 0000000..e2e5cc6 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.single.pass.cpp @@ -0,0 +1,222 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// + +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// Test unique_ptr converting move ctor + +// NOTE: unique_ptr does not provide converting constructors in c++03 +// UNSUPPORTED: c++98, c++03 + +#include +#include +#include +#include + +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +template +void checkReferenceDeleter(LHS& lhs, RHS& rhs) { + typedef typename LHS::deleter_type NewDel; + static_assert(std::is_reference::value, ""); + rhs.get_deleter().set_state(42); + assert(rhs.get_deleter().state() == 42); + assert(lhs.get_deleter().state() == 42); + lhs.get_deleter().set_state(99); + assert(lhs.get_deleter().state() == 99); + assert(rhs.get_deleter().state() == 99); +} + +template +void checkDeleter(LHS& lhs, RHS& rhs, int LHSVal, int RHSVal) { + assert(lhs.get_deleter().state() == LHSVal); + assert(rhs.get_deleter().state() == RHSVal); +} + +template +void checkCtor(LHS& lhs, RHS& rhs, A* RHSVal) { + assert(lhs.get() == RHSVal); + assert(rhs.get() == nullptr); + assert(A::count == 1); + assert(B::count == 1); +} + +void checkNoneAlive() { + assert(A::count == 0); + assert(B::count == 0); +} + +template +struct NCConvertingDeleter { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template + NCConvertingDeleter(NCConvertingDeleter&&) {} + + void operator()(T*) const {} +}; + +template +struct NCConvertingDeleter { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template + NCConvertingDeleter(NCConvertingDeleter&&) {} + + void operator()(T*) const {} +}; + +struct NCGenericDeleter { + NCGenericDeleter() = default; + NCGenericDeleter(NCGenericDeleter const&) = delete; + NCGenericDeleter(NCGenericDeleter&&) = default; + + void operator()(void*) const {} +}; + +void test_sfinae() { + using DA = NCConvertingDeleter; // non-copyable deleters + using DB = NCConvertingDeleter; + using UA = std::unique_ptr; + using UB = std::unique_ptr; + using UAD = std::unique_ptr; + using UBD = std::unique_ptr; + { // cannot move from an lvalue + static_assert(std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } + { // cannot move if the deleter-types cannot convert + static_assert(std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr; + using UB1 = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr; + using UB1 = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + } + { // cannot move-convert from unique_ptr + using UA1 = std::unique_ptr; + using UA2 = std::unique_ptr; + using UB1 = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } + { // cannot move-convert from unique_ptr + using UA1 = std::unique_ptr; + using UA2 = std::unique_ptr; + using UB1 = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } +} + +int main() { + { + typedef std::unique_ptr APtr; + typedef std::unique_ptr BPtr; + { // explicit + BPtr b(new B); + A* p = b.get(); + APtr a(std::move(b)); + checkCtor(a, b, p); + } + checkNoneAlive(); + { // implicit + BPtr b(new B); + A* p = b.get(); + APtr a = std::move(b); + checkCtor(a, b, p); + } + checkNoneAlive(); + } + { // test with moveable deleters + typedef std::unique_ptr > APtr; + typedef std::unique_ptr > BPtr; + { + Deleter del(5); + BPtr b(new B, std::move(del)); + A* p = b.get(); + APtr a(std::move(b)); + checkCtor(a, b, p); + checkDeleter(a, b, 5, 0); + } + checkNoneAlive(); + { + Deleter del(5); + BPtr b(new B, std::move(del)); + A* p = b.get(); + APtr a = std::move(b); + checkCtor(a, b, p); + checkDeleter(a, b, 5, 0); + } + checkNoneAlive(); + } + { // test with reference deleters + typedef std::unique_ptr&> APtr; + typedef std::unique_ptr&> BPtr; + NCDeleter del(5); + { + BPtr b(new B, del); + A* p = b.get(); + APtr a(std::move(b)); + checkCtor(a, b, p); + checkReferenceDeleter(a, b); + } + checkNoneAlive(); + { + BPtr b(new B, del); + A* p = b.get(); + APtr a = std::move(b); + checkCtor(a, b, p); + checkReferenceDeleter(a, b); + } + checkNoneAlive(); + } + { + typedef std::unique_ptr > APtr; + typedef std::unique_ptr&> BPtr; + CDeleter del(5); + { + BPtr b(new B, del); + A* p = b.get(); + APtr a(std::move(b)); + checkCtor(a, b, p); + checkDeleter(a, b, 5, 5); + } + checkNoneAlive(); + { + BPtr b(new B, del); + A* p = b.get(); + APtr a = std::move(b); + checkCtor(a, b, p); + checkDeleter(a, b, 5, 5); + } + checkNoneAlive(); + } + test_sfinae(); +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/null.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/null.pass.cpp new file mode 100644 index 0000000..8bc8a57 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/null.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// unique_ptr + +// FIXME(EricWF): This test contains tests for constructing a unique_ptr from NULL. +// The behavior demonstrated in this test is not meant to be standard; It simply +// tests the current status quo in libc++. + +#include +#include + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +template +void test_pointer_ctor() { + { + std::unique_ptr p(0); + assert(p.get() == 0); + } + { + std::unique_ptr > p(0); + assert(p.get() == 0); + assert(p.get_deleter().state() == 0); + } +} + +template +void test_pointer_deleter_ctor() { + { + std::default_delete d; + std::unique_ptr p(0, d); + assert(p.get() == 0); + } + { + std::unique_ptr > p(0, Deleter(5)); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } + { + NCDeleter d(5); + std::unique_ptr&> p(0, d); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } + { + NCConstDeleter d(5); + std::unique_ptr const&> p(0, d); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +} + +int main() { + { + // test_pointer_ctor(); + test_pointer_deleter_ctor(); + } + { + test_pointer_ctor(); + test_pointer_deleter_ctor(); + } +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp new file mode 100644 index 0000000..8e4ee7b --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp @@ -0,0 +1,117 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// unique_ptr(nullptr_t); + +#include +#include + +#include "test_macros.h" +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +#include "test_workarounds.h" // For TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES + +// default unique_ptr ctor should only require default Deleter ctor +class DefaultDeleter { + int state_; + + DefaultDeleter(DefaultDeleter&); + DefaultDeleter& operator=(DefaultDeleter&); + +public: + DefaultDeleter() : state_(5) {} + + int state() const { return state_; } + + void operator()(void*) {} +}; + +#if TEST_STD_VER >= 11 +struct NonDefaultDeleter { + NonDefaultDeleter() = delete; + void operator()(void*) const {} +}; +#endif + +template +void test_basic() { + { + std::unique_ptr p(nullptr); + assert(p.get() == 0); + } + { + std::unique_ptr p(nullptr); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +#if TEST_STD_VER >= 11 + { + using U1 = std::unique_ptr; + using U2 = std::unique_ptr >; + static_assert(std::is_nothrow_constructible::value, + ""); + static_assert(std::is_nothrow_constructible::value, + ""); + } +#endif +} + +template +void test_sfinae() { +#if TEST_STD_VER >= 11 && !defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES) + { // the constructor does not participate in overload resultion when + // the deleter is a pointer type + using U = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + } + { // the constructor does not participate in overload resolution when + // the deleter is not default constructible + using Del = CDeleter; + using U1 = std::unique_ptr; + using U2 = std::unique_ptr; + using U3 = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } +#endif +} + +DEFINE_AND_RUN_IS_INCOMPLETE_TEST({ + { doIncompleteTypeTest(0, nullptr); } + checkNumIncompleteTypeAlive(0); + { + doIncompleteTypeTest >(0, + nullptr); + } + checkNumIncompleteTypeAlive(0); + { doIncompleteTypeTest(0, nullptr); } + checkNumIncompleteTypeAlive(0); + { + doIncompleteTypeTest >( + 0, nullptr); + } + checkNumIncompleteTypeAlive(0); +}) + +int main() { + { + test_basic(); + test_sfinae(); + } + { + test_basic(); + test_sfinae(); + } +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp new file mode 100644 index 0000000..3ae77d3 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp @@ -0,0 +1,167 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +//============================================================================= +// TESTING std::unique_ptr::unique_ptr(pointer) +// +// Concerns: +// 1 The pointer constructor works for any default constructible deleter types. +// 2 The pointer constructor accepts pointers to derived types. +// 2 The stored type 'T' is allowed to be incomplete. +// +// Plan +// 1 Construct unique_ptr's with a pointer to 'T' and various deleter +// types (C-1) +// 2 Construct unique_ptr's with a pointer to 'D' and various deleter +// types where 'D' is derived from 'T'. (C-1,2) +// 3 Construct a unique_ptr with a pointer to 'T' and various deleter +// types where 'T' is an incomplete type (C-1,3) + +// Test unique_ptr(pointer) ctor + +#include +#include + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +#include "test_workarounds.h" // For TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES + +// unique_ptr(pointer) ctor should only require default Deleter ctor + +template +void test_pointer() { + typedef typename std::conditional::type ValueT; + const int expect_alive = IsArray ? 5 : 1; +#if TEST_STD_VER >= 11 + { + using U1 = std::unique_ptr; + using U2 = std::unique_ptr >; + static_assert(std::is_nothrow_constructible::value, ""); + static_assert(std::is_nothrow_constructible::value, ""); + } +#endif + { + A* p = newValue(expect_alive); + assert(A::count == expect_alive); + std::unique_ptr s(p); + assert(s.get() == p); + } + assert(A::count == 0); + { + A* p = newValue(expect_alive); + assert(A::count == expect_alive); + std::unique_ptr > s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); +} + +void test_derived() { + { + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr s(p); + assert(s.get() == p); + } + assert(A::count == 0); + assert(B::count == 0); + { + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr > s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} + +#if TEST_STD_VER >= 11 +struct NonDefaultDeleter { + NonDefaultDeleter() = delete; + void operator()(void*) const {} +}; + +struct GenericDeleter { + void operator()(void*) const; +}; +#endif + +template +void test_sfinae() { +#if TEST_STD_VER >= 11 && !defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES) + { // the constructor does not participate in overload resultion when + // the deleter is a pointer type + using U = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + } + { // the constructor does not participate in overload resolution when + // the deleter is not default constructible + using Del = CDeleter; + using U1 = std::unique_ptr; + using U2 = std::unique_ptr; + using U3 = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } +#endif +} + +static void test_sfinae_runtime() { +#if TEST_STD_VER >= 11 + { // the constructor does not participate in overload resolution when + // a base <-> derived conversion would occur. + using UA = std::unique_ptr; + using UAD = std::unique_ptr; + using UAC = std::unique_ptr; + using UB = std::unique_ptr; + using UBD = std::unique_ptr; + using UBC = std::unique_ptr; + + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } +#endif +} + +DEFINE_AND_RUN_IS_INCOMPLETE_TEST({ + { doIncompleteTypeTest(1, getNewIncomplete()); } + checkNumIncompleteTypeAlive(0); + { + doIncompleteTypeTest >( + 1, getNewIncomplete()); + } + checkNumIncompleteTypeAlive(0); +}) + +int main() { + { + test_pointer(); + test_derived(); + test_sfinae(); + } + { + test_pointer(); + test_sfinae(); + test_sfinae_runtime(); + } +} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.fail.cpp similarity index 59% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.fail.cpp index ad64b5e..4ef4f14 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.fail.cpp @@ -19,12 +19,17 @@ #include +#include "test_workarounds.h" + struct Deleter { - void operator()(int* p) const {delete p;} + void operator()(int* p) const { delete p; } }; -int main() -{ - // expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}} - std::unique_ptr s((int*)nullptr, Deleter()); // expected-note {{requested here}} +int main() { +#if defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES) +// expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}} +#else +// expected-error@+2 {{call to deleted constructor of 'std::unique_ptr}} +#endif + std::unique_ptr s((int*)nullptr, Deleter()); } diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.pass.cpp new file mode 100644 index 0000000..601751e --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.pass.cpp @@ -0,0 +1,307 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +//============================================================================= +// TESTING unique_ptr(pointer, deleter) +// +// Concerns: +// 1 unique_ptr(pointer, deleter&&) only requires a MoveConstructible deleter. +// 2 unique_ptr(pointer, deleter&) requires a CopyConstructible deleter. +// 3 unique_ptr(pointer, deleter) does not require a CopyConstructible deleter. +// 4 unique_ptr(pointer, deleter) does not require a CopyConstructible deleter. +// 5 unique_ptr(pointer, deleter) should work for derived pointers. +// 6 unique_ptr(pointer, deleter) should work with function pointers. +// 7 unique_ptr should work. + +#include +#include + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +#include "test_workarounds.h" // For TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES + +bool my_free_called = false; + +void my_free(void*) { my_free_called = true; } + +#if TEST_STD_VER >= 11 +struct DeleterBase { + void operator()(void*) const {} +}; +struct CopyOnlyDeleter : DeleterBase { + CopyOnlyDeleter() = default; + CopyOnlyDeleter(CopyOnlyDeleter const&) = default; + CopyOnlyDeleter(CopyOnlyDeleter&&) = delete; +}; +struct MoveOnlyDeleter : DeleterBase { + MoveOnlyDeleter() = default; + MoveOnlyDeleter(MoveOnlyDeleter&&) = default; +}; +struct NoCopyMoveDeleter : DeleterBase { + NoCopyMoveDeleter() = default; + NoCopyMoveDeleter(NoCopyMoveDeleter const&) = delete; +}; +#endif + +template +void test_sfinae() { +#if TEST_STD_VER >= 11 && !defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES) + typedef typename std::conditional::type VT; + { + using D = CopyOnlyDeleter; + using U = std::unique_ptr; + static_assert(std::is_constructible::value, ""); + static_assert(std::is_constructible::value, ""); + static_assert(std::is_constructible::value, ""); + // FIXME: __libcpp_compressed_pair attempts to perform a move even though + // it should only copy. + //D d; + //U u(nullptr, std::move(d)); + } + { + using D = MoveOnlyDeleter; + using U = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(std::is_constructible::value, ""); + D d; + U u(nullptr, std::move(d)); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr; + static_assert(std::is_constructible::value, ""); + static_assert(std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } +#endif +} + +template +void test_noexcept() { +#if TEST_STD_VER >= 11 + typedef typename std::conditional::type VT; + { + using D = CopyOnlyDeleter; + using U = std::unique_ptr; + static_assert(std::is_nothrow_constructible::value, ""); + static_assert(std::is_nothrow_constructible::value, ""); + static_assert(std::is_nothrow_constructible::value, ""); + } + { + using D = MoveOnlyDeleter; + using U = std::unique_ptr; + static_assert(std::is_nothrow_constructible::value, ""); + D d; + U u(nullptr, std::move(d)); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr; + static_assert(std::is_nothrow_constructible::value, ""); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr; + static_assert(std::is_nothrow_constructible::value, ""); + static_assert(std::is_nothrow_constructible::value, ""); + } +#endif +} + +void test_sfinae_runtime() { +#if TEST_STD_VER >= 11 && !defined(TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES) + { + using D = CopyOnlyDeleter; + using U = std::unique_ptr; + static_assert(std::is_constructible::value, ""); + static_assert(std::is_constructible::value, ""); + static_assert(std::is_constructible::value, ""); + + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + // FIXME: __libcpp_compressed_pair attempts to perform a move even though + // it should only copy. + //D d; + //U u(nullptr, std::move(d)); + } + { + using D = MoveOnlyDeleter; + using U = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(std::is_constructible::value, ""); + + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + D d; + U u(nullptr, std::move(d)); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr; + static_assert(!std::is_constructible::value, ""); + static_assert(std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr; + static_assert(std::is_constructible::value, ""); + static_assert(std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + static_assert(!std::is_constructible::value, ""); + } +#endif +} + +template +void test_basic() { + typedef typename std::conditional::type VT; + const int expect_alive = IsArray ? 5 : 1; + { // MoveConstructible deleter (C-1) + A* p = newValue(expect_alive); + assert(A::count == expect_alive); + std::unique_ptr > s(p, Deleter(5)); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + { // CopyConstructible deleter (C-2) + A* p = newValue(expect_alive); + assert(A::count == expect_alive); + CopyDeleter d(5); + std::unique_ptr > s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + { // Reference deleter (C-3) + A* p = newValue(expect_alive); + assert(A::count == expect_alive); + NCDeleter d(5); + std::unique_ptr&> s(p, d); + assert(s.get() == p); + assert(&s.get_deleter() == &d); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 6); + } + assert(A::count == 0); + { // Const Reference deleter (C-4) + A* p = newValue(expect_alive); + assert(A::count == expect_alive); + NCConstDeleter d(5); + std::unique_ptr const&> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + assert(&s.get_deleter() == &d); + } + assert(A::count == 0); + { // Void and function pointers (C-6,7) + typedef typename std::conditional::type VT2; + my_free_called = false; + { + int i = 0; + std::unique_ptr s(&i, my_free); + assert(s.get() == &i); + assert(s.get_deleter() == my_free); + assert(!my_free_called); + } + assert(my_free_called); + } +} + +void test_basic_single() { + assert(A::count == 0); + assert(B::count == 0); + { // Derived pointers (C-5) + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr > s(p, Deleter(5)); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); + { // Void and function pointers (C-6,7) + my_free_called = false; + { + int i = 0; + std::unique_ptr s(&i, my_free); + assert(s.get() == &i); + assert(s.get_deleter() == my_free); + assert(!my_free_called); + } + assert(my_free_called); + } +} + +int main() { + { + test_basic(); + test_basic_single(); + test_sfinae(); + test_noexcept(); + } + { + test_basic(); + test_sfinae(); + test_sfinae_runtime(); + test_noexcept(); + } +} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.dtor/null.pass.cpp similarity index 57% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.dtor/null.pass.cpp index 064f38c..5507e7e 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.dtor/null.pass.cpp @@ -16,29 +16,33 @@ #include #include -class Deleter -{ - int state_; +class Deleter { + int state_; - Deleter(Deleter&); - Deleter& operator=(Deleter&); + Deleter(Deleter&); + Deleter& operator=(Deleter&); public: - Deleter() : state_(0) {} + Deleter() : state_(0) {} - int state() const {return state_;} + int state() const { return state_; } - void operator()(void*) {++state_;} + void operator()(void*) { ++state_; } }; -int main() -{ - Deleter d; - assert(d.state() == 0); - { - std::unique_ptr p(0, d); +template +void test_basic() { + Deleter d; + assert(d.state() == 0); + { + std::unique_ptr p(0, d); assert(p.get() == 0); assert(&p.get_deleter() == &d); - } - assert(d.state() == 0); + } + assert(d.state() == 0); +} + +int main() { + test_basic(); + test_basic(); } diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/release.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/release.pass.cpp new file mode 100644 index 0000000..581340f --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/release.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// test release + +#include +#include + +#include "unique_ptr_test_helper.h" + +template +void test_basic() { + typedef typename std::conditional::type VT; + const int expect_alive = IsArray ? 3 : 1; + { + std::unique_ptr p(newValue(expect_alive)); + assert(A::count == expect_alive); + A* ap = p.get(); + A* a = p.release(); + assert(A::count == expect_alive); + assert(p.get() == nullptr); + assert(ap == a); + assert(a != nullptr); + + if (IsArray) + delete[] a; + else + delete a; + + assert(A::count == 0); + } + assert(A::count == 0); +} + +int main() { + test_basic(); + test_basic(); +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.pass.cpp new file mode 100644 index 0000000..302023b --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// test reset + +#include +#include + +#include "unique_ptr_test_helper.h" + +template +void test_basic() { + typedef typename std::conditional::type VT; + const int expect_alive = IsArray ? 3 : 1; + { + std::unique_ptr p(newValue(expect_alive)); + assert(A::count == expect_alive); + A* i = p.get(); + assert(i != nullptr); + p.reset(); + assert(A::count == 0); + assert(p.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr p(newValue(expect_alive)); + assert(A::count == expect_alive); + A* i = p.get(); + assert(i != nullptr); + A* new_value = newValue(expect_alive); + assert(A::count == (expect_alive * 2)); + p.reset(new_value); + assert(A::count == expect_alive); + } + assert(A::count == 0); +} + +int main() { + test_basic(); + test_basic(); +} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.runtime.fail.cpp similarity index 57% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.runtime.fail.cpp index 9ec9b95..0d067b9 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.runtime.fail.cpp @@ -11,29 +11,20 @@ // unique_ptr -// test op*() +// test reset #include #include -int main() -{ - { - std::unique_ptr p(new int [3]); - if (p) - ; - else - assert(false); - if (!p) - assert(false); - } - { +#include "unique_ptr_test_helper.h" + +int main() { + { + std::unique_ptr p; + p.reset(static_cast(nullptr)); // expected-error {{no matching member function for call to 'reset'}} + } + { std::unique_ptr p; - if (!p) - ; - else - assert(false); - if (p) - assert(false); - } + p.reset(static_cast(nullptr)); // expected-error {{no matching member function for call to 'reset'}} + } } diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.single.pass.cpp similarity index 67% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.single.pass.cpp index 2de7787..8f2a699 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.single.pass.cpp @@ -16,30 +16,10 @@ #include #include -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; +#include "unique_ptr_test_helper.h" -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { +int main() { + { std::unique_ptr p(new A); assert(A::count == 1); assert(B::count == 0); @@ -48,10 +28,10 @@ int main() p.reset(new B); assert(A::count == 1); assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); - { + } + assert(A::count == 0); + assert(B::count == 0); + { std::unique_ptr p(new B); assert(A::count == 1); assert(B::count == 1); @@ -60,7 +40,7 @@ int main() p.reset(new B); assert(A::count == 1); assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); + } + assert(A::count == 0); + assert(B::count == 0); } diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset_self.pass.cpp similarity index 76% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset_self.pass.cpp index 58b05ef..f838661 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset_self.pass.cpp @@ -15,15 +15,11 @@ #include -struct A -{ - std::unique_ptr ptr_; +struct A { + std::unique_ptr ptr_; - A() : ptr_(this) {} - void reset() {ptr_.reset();} + A() : ptr_(this) {} + void reset() { ptr_.reset(); } }; -int main() -{ - (new A)->reset(); -} +int main() { (new A)->reset(); } diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/swap.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/swap.pass.cpp new file mode 100644 index 0000000..0316398 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/swap.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// test swap + +#include +#include + +#include "unique_ptr_test_helper.h" + +struct TT { + int state_; + static int count; + TT() : state_(-1) { ++count; } + explicit TT(int i) : state_(i) { ++count; } + TT(const TT& a) : state_(a.state_) { ++count; } + TT& operator=(const TT& a) { + state_ = a.state_; + return *this; + } + ~TT() { --count; } + + friend bool operator==(const TT& x, const TT& y) { + return x.state_ == y.state_; + } +}; + +int TT::count = 0; + +template +typename std::remove_all_extents::type* newValueInit(int size, + int new_value) { + typedef typename std::remove_all_extents::type VT; + VT* p = newValue(size); + for (int i = 0; i < size; ++i) + (p + i)->state_ = new_value; + return p; +} + +template +void test_basic() { + typedef typename std::conditional::type VT; + const int expect_alive = IsArray ? 5 : 1; + { + TT* p1 = newValueInit(expect_alive, 1); + std::unique_ptr > s1(p1, Deleter(1)); + TT* p2 = newValueInit(expect_alive, 2); + std::unique_ptr > s2(p2, Deleter(2)); + assert(s1.get() == p1); + assert(*s1.get() == TT(1)); + assert(s1.get_deleter().state() == 1); + assert(s2.get() == p2); + assert(*s2.get() == TT(2)); + assert(s2.get_deleter().state() == 2); + s1.swap(s2); + assert(s1.get() == p2); + assert(*s1.get() == TT(2)); + assert(s1.get_deleter().state() == 2); + assert(s2.get() == p1); + assert(*s2.get() == TT(1)); + assert(s2.get_deleter().state() == 1); + assert(TT::count == (expect_alive * 2)); + } + assert(TT::count == 0); +} + +int main() { + test_basic(); + test_basic(); +} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.runtime.fail.cpp similarity index 57% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.runtime.fail.cpp index d5c7445..b05fb71 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.runtime.fail.cpp @@ -16,24 +16,9 @@ #include #include -int main() -{ - { - std::unique_ptr p(new int(3)); - if (p) - ; - else - assert(false); - if (!p) - assert(false); - } - { - std::unique_ptr p; - if (!p) - ; - else - assert(false); - if (p) - assert(false); - } +int main() { + std::unique_ptr p(new int(3)); + const std::unique_ptr& cp = p; + (void)(*p); // expected-error {{indirection requires pointer operand ('std::unique_ptr' invalid)}} + (void)(*cp); // expected-error {{indirection requires pointer operand ('const std::unique_ptr' invalid)}} } diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.single.pass.cpp similarity index 85% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.single.pass.cpp index 9d0cfca..b2d3da4 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.single.pass.cpp @@ -16,8 +16,7 @@ #include #include -int main() -{ - std::unique_ptr p(new int(3)); - assert(*p == 3); +int main() { + std::unique_ptr p(new int(3)); + assert(*p == 3); } diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/explicit_bool.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/explicit_bool.pass.cpp new file mode 100644 index 0000000..9a6d6c6 --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/explicit_bool.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// test op*() + +#include +#include + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +template +void doTest(UPtr& p, bool ExpectTrue) { + if (p) + assert(ExpectTrue); + else + assert(!ExpectTrue); + + if (!p) + assert(!ExpectTrue); + else + assert(ExpectTrue); +} + +template +void test_basic() { + typedef typename std::conditional::type VT; + typedef std::unique_ptr U; + { + static_assert((std::is_constructible::value), ""); + static_assert((std::is_constructible::value), ""); + } +#if TEST_STD_VER >= 11 + { + static_assert(!std::is_convertible::value, ""); + static_assert(!std::is_convertible::value, ""); + } +#endif + { + U p(newValue(1)); + U const& cp = p; + doTest(p, true); + doTest(cp, true); + } + { + U p; + const U& cp = p; + doTest(p, false); + doTest(cp, false); + } +} + +int main() { + test_basic(); + test_basic(); +} diff --git a/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get.pass.cpp new file mode 100644 index 0000000..518e31c --- /dev/null +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// + +// unique_ptr + +// test get + +#include +#include + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +template +void test_basic() { + typedef typename std::conditional::type VT; + typedef const VT CVT; + { + typedef std::unique_ptr U; + int* p = newValue(1); + U s(p); + U const& sc = s; + ASSERT_SAME_TYPE(decltype(s.get()), int*); + ASSERT_SAME_TYPE(decltype(sc.get()), int*); + assert(s.get() == p); + assert(sc.get() == s.get()); + } + { + typedef std::unique_ptr U; + const int* p = newValue(1); + U s(p); + U const& sc = s; + ASSERT_SAME_TYPE(decltype(s.get()), const int*); + ASSERT_SAME_TYPE(decltype(sc.get()), const int*); + assert(s.get() == p); + assert(sc.get() == s.get()); + } +} + +int main() { + test_basic(); + test_basic(); +} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get_deleter.pass.cpp similarity index 80% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get_deleter.pass.cpp index 14c4d11..6a00d14 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get_deleter.pass.cpp @@ -26,17 +26,19 @@ struct Deleter { int test() const { return 6; } }; -int main() { +template +void test_basic() { + typedef typename std::conditional::type VT; { std::unique_ptr p; assert(p.get_deleter().test() == 5); } { - const std::unique_ptr p; + const std::unique_ptr p; assert(p.get_deleter().test() == 6); } { - typedef std::unique_ptr UPtr; + typedef std::unique_ptr UPtr; const Deleter d; UPtr p(nullptr, d); const UPtr& cp = p; @@ -46,7 +48,7 @@ int main() { assert(cp.get_deleter().test() == 6); } { - typedef std::unique_ptr UPtr; + typedef std::unique_ptr UPtr; Deleter d; UPtr p(nullptr, d); const UPtr& cp = p; @@ -56,3 +58,8 @@ int main() { assert(cp.get_deleter().test() == 5); } } + +int main() { + test_basic(); + test_basic(); +} diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.runtime.fail.cpp similarity index 51% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.runtime.fail.cpp index 1c90ba7..d66af05 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.runtime.fail.cpp @@ -16,15 +16,17 @@ #include #include -struct A -{ - int i_; - - A() : i_(7) {} +struct V { + int member; }; -int main() -{ - std::unique_ptr p(new A); - assert(p->i_ == 7); +int main() { + std::unique_ptr p; + std::unique_ptr const& cp = p; + + p->member; // expected-error {{member reference type 'std::unique_ptr' is not a pointer}} + // expected-error@-1 {{no member named 'member'}} + + cp->member; // expected-error {{member reference type 'const std::unique_ptr' is not a pointer}} + // expected-error@-1 {{no member named 'member'}} } diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.single.pass.cpp similarity index 79% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.single.pass.cpp index 47de8f6..8bed9dd 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.single.pass.cpp @@ -16,15 +16,13 @@ #include #include -struct A -{ - int i_; +struct A { + int i_; - A() : i_(7) {} + A() : i_(7) {} }; -int main() -{ - std::unique_ptr p(new A); - assert(p->i_ == 7); +int main() { + std::unique_ptr p(new A); + assert(p->i_ == 7); } diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.runtime.pass.cpp similarity index 50% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.runtime.pass.cpp index 21e829c..b47c35a 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.runtime.pass.cpp @@ -16,32 +16,33 @@ #include #include -class A -{ - int state_; - static int next_; +class A { + int state_; + static int next_; + public: - A() : state_(++next_) {} - int get() const {return state_;} + A() : state_(++next_) {} + int get() const { return state_; } - friend bool operator==(const A& x, int y) - {return x.state_ == y;} + friend bool operator==(const A& x, int y) { return x.state_ == y; } - A& operator=(int i) {state_ = i; return *this;} + A& operator=(int i) { + state_ = i; + return *this; + } }; int A::next_ = 0; -int main() -{ - std::unique_ptr p(new A[3]); - assert(p[0] == 1); - assert(p[1] == 2); - assert(p[2] == 3); - p[0] = 3; - p[1] = 2; - p[2] = 1; - assert(p[0] == 3); - assert(p[1] == 2); - assert(p[2] == 1); +int main() { + std::unique_ptr p(new A[3]); + assert(p[0] == 1); + assert(p[1] == 2); + assert(p[2] == 3); + p[0] = 3; + p[1] = 2; + p[2] = 1; + assert(p[0] == 3); + assert(p[1] == 2); + assert(p[2] == 1); } diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.single.fail.cpp similarity index 57% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.single.fail.cpp index 2ae0659..529749d 100644 --- a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp +++ b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.single.fail.cpp @@ -11,14 +11,14 @@ // unique_ptr -// test get +// test op[](size_t) #include #include -int main() -{ - int* p = new int[3]; - std::unique_ptr s(p); - assert(s.get() == p); +int main() { + std::unique_ptr p(new int[3]); + std::unique_ptr const& cp = p; + p[0]; // expected-error {{type 'std::unique_ptr' does not provide a subscript operator}} + cp[1]; // expected-error {{type 'const std::unique_ptr' does not provide a subscript operator}} } diff --git a/libcxx/test/std/utilities/memory/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 similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp diff --git a/libcxx/test/std/utilities/memory/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 similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp diff --git a/libcxx/test/std/utilities/memory/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 similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp diff --git a/libcxx/test/std/utilities/memory/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 similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp diff --git a/libcxx/test/std/utilities/memory/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 similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp diff --git a/libcxx/test/std/utilities/memory/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 similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/nothing_to_do.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/nothing_to_do.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/eq.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/eq.pass.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/rel.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/rel.pass.cpp diff --git a/libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp b/libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/swap.pass.cpp similarity index 100% rename from libcxx/test/std/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp rename to libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/swap.pass.cpp diff --git a/libcxx/test/support/test_workarounds.h b/libcxx/test/support/test_workarounds.h index affdd10..02982ba 100644 --- a/libcxx/test/support/test_workarounds.h +++ b/libcxx/test/support/test_workarounds.h @@ -17,4 +17,12 @@ # define TEST_WORKAROUND_C1XX_BROKEN_NULLPTR_CONVERSION_OPERATOR #endif +// FIXME(EricWF): Remove this. This macro guards tests for upcoming changes +// and fixes to unique_ptr. Until the changes have been implemented in trunk +// the tests have to be disabled. However the tests have been left in until +// then so they can be used by other standard libraries. +#if defined(_LIBCPP_VERSION) +# define TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES +#endif + #endif // SUPPORT_TEST_WORKAROUNDS_H diff --git a/libcxx/test/support/unique_ptr_test_helper.h b/libcxx/test/support/unique_ptr_test_helper.h new file mode 100644 index 0000000..390ff14 --- /dev/null +++ b/libcxx/test/support/unique_ptr_test_helper.h @@ -0,0 +1,164 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#ifndef TEST_SUPPORT_UNIQUE_PTR_TEST_HELPER_H +#define TEST_SUPPORT_UNIQUE_PTR_TEST_HELPER_H + +#include +#include + +#include "test_macros.h" +#include "deleter_types.h" + +struct A { + static int count; + A() { ++count; } + A(const A&) { ++count; } + virtual ~A() { --count; } +}; + +int A::count = 0; + +struct B : public A { + static int count; + B() { ++count; } + B(const B&) { ++count; } + virtual ~B() { --count; } +}; + +int B::count = 0; + +template +typename std::enable_if::value, T*>::type +newValue(int num_elements) { + assert(num_elements == 1); + return new T; +} + +template +typename std::enable_if::value, + typename std::remove_all_extents::type*>::type +newValue(int num_elements) { + typedef typename std::remove_all_extents::type VT; + assert(num_elements >= 1); + return new VT[num_elements]; +} + +struct IncompleteType; + +void checkNumIncompleteTypeAlive(int i); +int getNumIncompleteTypeAlive(); +IncompleteType* getNewIncomplete(); +IncompleteType* getNewIncompleteArray(int size); + +#if TEST_STD_VER >= 11 +template +struct args_is_this_type : std::false_type {}; + +template +struct args_is_this_type : std::is_same::type> {}; +#endif + +template > +struct StoresIncomplete { + static_assert((std::is_same::value || + std::is_same::value), ""); + + std::unique_ptr m_ptr; + +#if TEST_STD_VER >= 11 + StoresIncomplete(StoresIncomplete const&) = delete; + StoresIncomplete(StoresIncomplete&&) = default; + + template + StoresIncomplete(Args&&... args) : m_ptr(std::forward(args)...) { + static_assert(!args_is_this_type::value, ""); + } +#else +private: + StoresIncomplete(); + StoresIncomplete(StoresIncomplete const&); +public: +#endif + + ~StoresIncomplete(); + + IncompleteType* get() const { return m_ptr.get(); } + Del& get_deleter() { return m_ptr.get_deleter(); } +}; + +#if TEST_STD_VER >= 11 +template , class... Args> +void doIncompleteTypeTest(int expect_alive, Args&&... ctor_args) { + using ValueT = typename std::remove_all_extents::type; + + + if (expect_alive == 0) + checkNumIncompleteTypeAlive(0); + else + checkNumIncompleteTypeAlive(expect_alive); + + { + StoresIncomplete sptr(std::forward(ctor_args)...); + checkNumIncompleteTypeAlive(expect_alive); + if (expect_alive == 0) + assert(sptr.get() == nullptr); + else + assert(sptr.get() != nullptr); + } + checkNumIncompleteTypeAlive(0); +} +#endif + +#define INCOMPLETE_TEST_EPILOGUE() \ + int is_incomplete_test_anchor = is_incomplete_test(); \ + \ + struct IncompleteType { \ + static int count; \ + IncompleteType() { ++count; } \ + ~IncompleteType() { --count; } \ + }; \ + \ + int IncompleteType::count = 0; \ + \ + void checkNumIncompleteTypeAlive(int i) { \ + assert(IncompleteType::count == i); \ + } \ + int getNumIncompleteTypeAlive() { return IncompleteType::count; } \ + IncompleteType* getNewIncomplete() { return new IncompleteType; } \ + IncompleteType* getNewIncompleteArray(int size) { \ + return new IncompleteType[size]; \ + } \ + \ + template \ + StoresIncomplete::~StoresIncomplete() {} +# + +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wvariadic-macros" +#endif + +#if TEST_STD_VER >= 11 +#define DEFINE_AND_RUN_IS_INCOMPLETE_TEST(...) \ + static int is_incomplete_test() { __VA_ARGS__ return 0; } \ + INCOMPLETE_TEST_EPILOGUE() +#else +#define DEFINE_AND_RUN_IS_INCOMPLETE_TEST(...) \ + static int is_incomplete_test() { return 0; } \ + INCOMPLETE_TEST_EPILOGUE() +#endif + +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + +#endif // TEST_SUPPORT_UNIQUE_PTR_TEST_HELPER_H -- 2.7.4