]> git.saurik.com Git - apple/xnu.git/blame - tests/intrusive_shared_ptr_src/operator.bool.cpp
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / intrusive_shared_ptr_src / operator.bool.cpp
CommitLineData
f427ee49
A
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
11struct T {
12 int i;
13};
14
15template <typename T>
16static void
17tests()
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
42T_DECL(operator_bool, "intrusive_shared_ptr.operator.bool") {
43 tests<T>();
44 tests<T const>();
45}