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