1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 
11 // <coroutine>
12 
13 // template <class Promise = void>
14 // struct coroutine_handle;
15 
16 // constexpr explicit operator bool() const noexcept
17 
18 #include <coroutine>
19 #include <type_traits>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 
24 template <class C>
do_test()25 constexpr bool do_test() {
26   static_assert(std::is_nothrow_constructible<bool, C>::value, "");
27   static_assert(!std::is_convertible<C, bool>::value, "");
28   {
29     constexpr C c;
30     static_assert(bool(c) == false, "");
31   }
32   { // null case
33     const C c = {};
34     ASSERT_NOEXCEPT(bool(c));
35     assert(c.address() == nullptr);
36     assert(bool(c) == false);
37   }
38   { // non-null case
39     char dummy = 42;
40     C c = C::from_address((void*)&dummy);
41     assert(c.address() == &dummy);
42     assert(bool(c) == true);
43   }
44   return true;
45 }
46 
main(int,char **)47 int main(int, char**)
48 {
49   do_test<std::coroutine_handle<>>();
50   do_test<std::coroutine_handle<int>>();
51   static_assert(do_test<std::coroutine_handle<>>());
52   static_assert(do_test<std::coroutine_handle<int>>());
53 
54   return 0;
55 }
56