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