1bb611c8fSApple OSS Distributions // 2bb611c8fSApple OSS Distributions // Tests for 3bb611c8fSApple OSS Distributions // pointer get() const noexcept; 4bb611c8fSApple OSS Distributions // 5bb611c8fSApple OSS Distributions 6bb611c8fSApple OSS Distributions #include <libkern/c++/intrusive_shared_ptr.h> 7bb611c8fSApple OSS Distributions #include "test_policy.h" 8bb611c8fSApple OSS Distributions #include <darwintest.h> 9bb611c8fSApple OSS Distributions #include <utility> 10bb611c8fSApple OSS Distributions 11bb611c8fSApple OSS Distributions struct T { 12bb611c8fSApple OSS Distributions int i; 13bb611c8fSApple OSS Distributions }; 14bb611c8fSApple OSS Distributions 15bb611c8fSApple OSS Distributions template <typename T> 16bb611c8fSApple OSS Distributions static constexpr auto can_call_get_on_temporary(int)17bb611c8fSApple OSS Distributionscan_call_get_on_temporary(int)->decltype(std::declval<test_shared_ptr<T> >().get(), bool ()) 18bb611c8fSApple OSS Distributions { 19bb611c8fSApple OSS Distributions return true; 20bb611c8fSApple OSS Distributions } 21bb611c8fSApple OSS Distributions 22bb611c8fSApple OSS Distributions template <typename T> 23bb611c8fSApple OSS Distributions static constexpr auto can_call_get_on_temporary(...)24bb611c8fSApple OSS Distributionscan_call_get_on_temporary(...)->bool 25bb611c8fSApple OSS Distributions { 26bb611c8fSApple OSS Distributions return false; 27bb611c8fSApple OSS Distributions } 28bb611c8fSApple OSS Distributions 29bb611c8fSApple OSS Distributions template <typename T> 30bb611c8fSApple OSS Distributions static void tests()31bb611c8fSApple OSS Distributionstests() 32bb611c8fSApple OSS Distributions { 33bb611c8fSApple OSS Distributions { 34bb611c8fSApple OSS Distributions T obj{3}; 35bb611c8fSApple OSS Distributions tracking_policy::reset(); 36bb611c8fSApple OSS Distributions tracked_shared_ptr<T> const ptr(&obj, libkern::retain); 37bb611c8fSApple OSS Distributions T* raw = ptr.get(); 38bb611c8fSApple OSS Distributions CHECK(raw == &obj); 39bb611c8fSApple OSS Distributions CHECK(ptr.get() == raw); // ptr didn't change 40bb611c8fSApple OSS Distributions CHECK(tracking_policy::retains == 1); 41bb611c8fSApple OSS Distributions CHECK(tracking_policy::releases == 0); 42bb611c8fSApple OSS Distributions } 43bb611c8fSApple OSS Distributions 44bb611c8fSApple OSS Distributions static_assert(!can_call_get_on_temporary<T>(int{}), ""); 45bb611c8fSApple OSS Distributions } 46bb611c8fSApple OSS Distributions 47*8d741a5dSApple OSS Distributions T_DECL(get, "intrusive_shared_ptr.get", T_META_TAG_VM_PREFERRED) { 48bb611c8fSApple OSS Distributions tests<T>(); 49bb611c8fSApple OSS Distributions tests<T const>(); 50bb611c8fSApple OSS Distributions } 51