1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03
16 // Test unique_ptr move assignment
18 // test move assignment. Should only require a MoveConstructible deleter, or if
19 // deleter is a reference, not even that.
25 #include "deleter_types.h"
26 #include "unique_ptr_test_helper.h"
28 struct GenericDeleter {
29 void operator()(void*) const;
32 template <bool IsArray>
34 typedef typename std::conditional<IsArray, A[], A>::type VT;
35 const int expect_alive = IsArray ? 5 : 1;
37 std::unique_ptr<VT> s1(newValue<VT>(expect_alive));
39 std::unique_ptr<VT> s2(newValue<VT>(expect_alive));
40 assert(A::count == (expect_alive * 2));
42 assert(A::count == expect_alive);
43 assert(s2.get() == p);
44 assert(s1.get() == 0);
46 assert(A::count == 0);
48 std::unique_ptr<VT, Deleter<VT> > s1(newValue<VT>(expect_alive),
51 std::unique_ptr<VT, Deleter<VT> > s2(newValue<VT>(expect_alive));
52 assert(A::count == (expect_alive * 2));
54 assert(s2.get() == p);
55 assert(s1.get() == 0);
56 assert(A::count == expect_alive);
57 assert(s2.get_deleter().state() == 5);
58 assert(s1.get_deleter().state() == 0);
60 assert(A::count == 0);
63 std::unique_ptr<VT, CDeleter<VT>&> s1(newValue<VT>(expect_alive), d1);
66 std::unique_ptr<VT, CDeleter<VT>&> s2(newValue<VT>(expect_alive), d2);
68 assert(s2.get() == p);
69 assert(s1.get() == 0);
70 assert(A::count == expect_alive);
71 assert(d1.state() == 5);
72 assert(d2.state() == 5);
74 assert(A::count == 0);
77 template <bool IsArray>
79 typedef typename std::conditional<IsArray, int[], int>::type VT;
81 typedef std::unique_ptr<VT> U;
82 static_assert(!std::is_assignable<U, U&>::value, "");
83 static_assert(!std::is_assignable<U, const U&>::value, "");
84 static_assert(!std::is_assignable<U, const U&&>::value, "");
85 static_assert(std::is_nothrow_assignable<U, U&&>::value, "");
88 typedef std::unique_ptr<VT, GenericDeleter> U;
89 static_assert(!std::is_assignable<U, U&>::value, "");
90 static_assert(!std::is_assignable<U, const U&>::value, "");
91 static_assert(!std::is_assignable<U, const U&&>::value, "");
92 static_assert(std::is_nothrow_assignable<U, U&&>::value, "");
95 typedef std::unique_ptr<VT, NCDeleter<VT>&> U;
96 static_assert(!std::is_assignable<U, U&>::value, "");
97 static_assert(!std::is_assignable<U, const U&>::value, "");
98 static_assert(!std::is_assignable<U, const U&&>::value, "");
99 static_assert(std::is_nothrow_assignable<U, U&&>::value, "");
102 typedef std::unique_ptr<VT, const NCDeleter<VT>&> U;
103 static_assert(!std::is_assignable<U, U&>::value, "");
104 static_assert(!std::is_assignable<U, const U&>::value, "");
105 static_assert(!std::is_assignable<U, const U&&>::value, "");
106 static_assert(std::is_nothrow_assignable<U, U&&>::value, "");
113 test_basic</*IsArray*/ false>();
114 test_sfinae<false>();
117 test_basic</*IsArray*/ true>();