// // Tests for // template // intrusive_shared_ptr(intrusive_shared_ptr&& other); // // intrusive_shared_ptr(intrusive_shared_ptr&& other); // #include #include #include #include #include #include "test_policy.h" struct Base { int i; }; struct Derived : Base { }; struct Base1 { int i; }; struct Base2 { long l; }; struct DerivedMultiple : Base1, Base2 { DerivedMultiple(int i) : Base1{i}, Base2{i + 10} { } }; struct Unrelated { }; template static void tests() { Stored obj{3}; // Test with non-null pointers { test_policy::retain_count = 0; libkern::intrusive_shared_ptr from(&obj, libkern::retain); CHECK(test_policy::retain_count == 1); CHECK(from.get() == &obj); libkern::intrusive_shared_ptr to(std::move(from)); // explicit CHECK(test_policy::retain_count == 1); CHECK(to.get() == &obj); CHECK(from.get() == nullptr); } { test_policy::retain_count = 0; libkern::intrusive_shared_ptr from(&obj, libkern::retain); CHECK(test_policy::retain_count == 1); CHECK(from.get() == &obj); libkern::intrusive_shared_ptr to{std::move(from)}; // explicit CHECK(test_policy::retain_count == 1); CHECK(to.get() == &obj); CHECK(from.get() == nullptr); } { test_policy::retain_count = 0; libkern::intrusive_shared_ptr from(&obj, libkern::retain); CHECK(test_policy::retain_count == 1); CHECK(from.get() == &obj); libkern::intrusive_shared_ptr to = std::move(from); // implicit CHECK(test_policy::retain_count == 1); CHECK(to.get() == &obj); CHECK(from.get() == nullptr); } // Test with a null pointer { test_policy::retain_count = 3; libkern::intrusive_shared_ptr from = nullptr; libkern::intrusive_shared_ptr to = std::move(from); CHECK(test_policy::retain_count == 3); CHECK(to.get() == nullptr); CHECK(from.get() == nullptr); } } T_DECL(ctor_move, "intrusive_shared_ptr.ctor.move", T_META_TAG_VM_PREFERRED) { tests(); tests(); tests(); tests(); tests(); tests(); tests(); tests(); tests(); tests(); // Make sure basic trait querying works static_assert(std::is_move_constructible_v >); // Make sure downcasts are disabled static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr&&>); static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr&&>); static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr&&>); static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr&&>); // Make sure const-casting away doesn't work static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr&&>); // Make sure casting to unrelated types doesn't work static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr&&>); static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr&&>); static_assert(!std::is_constructible_v, /*from*/ test_shared_ptr&&>); // Make sure constructing with different policies doesn't work static_assert(!std::is_constructible_v >, /*from*/ libkern::intrusive_shared_ptr >&&>); }