1*bb611c8fSApple OSS Distributions // 2*bb611c8fSApple OSS Distributions // Tests for 3*bb611c8fSApple OSS Distributions // explicit constexpr operator bool() const noexcept; 4*bb611c8fSApple OSS Distributions // 5*bb611c8fSApple OSS Distributions 6*bb611c8fSApple OSS Distributions #include <libkern/c++/intrusive_shared_ptr.h> 7*bb611c8fSApple OSS Distributions #include <type_traits> 8*bb611c8fSApple OSS Distributions #include <darwintest.h> 9*bb611c8fSApple OSS Distributions #include "test_policy.h" 10*bb611c8fSApple OSS Distributions 11*bb611c8fSApple OSS Distributions struct T { 12*bb611c8fSApple OSS Distributions int i; 13*bb611c8fSApple OSS Distributions }; 14*bb611c8fSApple OSS Distributions 15*bb611c8fSApple OSS Distributions template <typename T> 16*bb611c8fSApple OSS Distributions static void 17*bb611c8fSApple OSS Distributions tests() 18*bb611c8fSApple OSS Distributions { 19*bb611c8fSApple OSS Distributions T obj{3}; 20*bb611c8fSApple OSS Distributions 21*bb611c8fSApple OSS Distributions { 22*bb611c8fSApple OSS Distributions test_shared_ptr<T> const ptr(&obj, libkern::no_retain); 23*bb611c8fSApple OSS Distributions CHECK(static_cast<bool>(ptr)); 24*bb611c8fSApple OSS Distributions if (ptr) { 25*bb611c8fSApple OSS Distributions } else { 26*bb611c8fSApple OSS Distributions CHECK(false); 27*bb611c8fSApple OSS Distributions } 28*bb611c8fSApple OSS Distributions } 29*bb611c8fSApple OSS Distributions 30*bb611c8fSApple OSS Distributions { 31*bb611c8fSApple OSS Distributions test_shared_ptr<T> const ptr = nullptr; 32*bb611c8fSApple OSS Distributions CHECK(!static_cast<bool>(ptr)); 33*bb611c8fSApple OSS Distributions if (!ptr) { 34*bb611c8fSApple OSS Distributions } else { 35*bb611c8fSApple OSS Distributions CHECK(false); 36*bb611c8fSApple OSS Distributions } 37*bb611c8fSApple OSS Distributions } 38*bb611c8fSApple OSS Distributions 39*bb611c8fSApple OSS Distributions static_assert(!std::is_convertible_v<test_shared_ptr<T>, bool>); 40*bb611c8fSApple OSS Distributions } 41*bb611c8fSApple OSS Distributions 42*bb611c8fSApple OSS Distributions T_DECL(operator_bool, "intrusive_shared_ptr.operator.bool") { 43*bb611c8fSApple OSS Distributions tests<T>(); 44*bb611c8fSApple OSS Distributions tests<T const>(); 45*bb611c8fSApple OSS Distributions } 46