#include "app.hpp" #include "compat/assert.hpp" #include "compat/borrowed-ptr.inl" namespace floormat { namespace { struct Foo {}; struct Bar : Foo {}; struct Baz {}; } // namespace // NOLINTBEGIN(*-use-anonymous-namespace) template struct detail_borrowed_ptr::control_block_impl; template struct detail_borrowed_ptr::control_block_impl; template struct detail_borrowed_ptr::control_block_impl; template bool operator==(const bptr&, const bptr&) noexcept; template bool operator==(const bptr&, const bptr&) noexcept; template bool operator==(const bptr&, const bptr&) noexcept; template class bptr; template class bptr; template class bptr; template bptr static_pointer_cast(const bptr&) noexcept; template bptr static_pointer_cast(const bptr&) noexcept; template bptr static_pointer_cast(const bptr&) noexcept; template bptr static_pointer_cast(const bptr&) noexcept; template bptr static_pointer_cast(const bptr&) noexcept; //template bptr static_pointer_cast(const bptr&) noexcept; // must fail //template bptr static_pointer_cast(const bptr&) noexcept; // must fail //template bptr static_pointer_cast(const bptr&) noexcept; // must fail // NOLINTEND(*-use-anonymous-namespace) namespace { int A_total = 0, A_alive = 0; // NOLINT struct A { int val, serial; explicit A(int val) : val{val}, serial{++A_total} { ++A_alive; } ~A() noexcept { --A_alive; fm_assert(A_alive >= 0); } }; void test1() { A_total = 0; A_alive = 0; auto p1 = bptr{InPlace, 1}; fm_assert(p1.use_count() == 1); fm_assert(p1.get()); fm_assert(A_total == 1); fm_assert(A_alive == 1); p1 = nullptr; fm_assert(p1.use_count() == 0); fm_assert(!p1.get()); fm_assert(A_total == 1); fm_assert(A_alive == 0); } void test2() { A_total = 0; A_alive = 0; auto p1 = bptr{InPlace, 2}; auto p2 = p1; fm_assert(p1.get()); fm_assert(p1.get() == p2.get()); fm_assert(p1->val == 2); fm_assert(p1->serial == 1); fm_assert(A_total == 1); fm_assert(A_alive == 1); p1 = nullptr; fm_assert(!p1.get()); fm_assert(p2.get()); fm_assert(p2->val == 2); fm_assert(p2->serial == 1); fm_assert(A_total == 1); fm_assert(A_alive == 1); p2 = nullptr; fm_assert(!p1.get()); fm_assert(!p2.get()); fm_assert(A_total == 1); fm_assert(A_alive == 0); } } // namespace void test_app::test_bptr() { test1(); test2(); } } // namespace floormat