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 // void destroy() const
17 
18 #include <coroutine>
19 #include <type_traits>
20 #include <memory>
21 #include <utility>
22 #include <cstdint>
23 #include <cassert>
24 
25 #include "test_macros.h"
26 
27 template <class H>
28 auto has_destroy_imp(H&& h, int) -> decltype(h.destroy(), std::true_type{});
29 template <class H>
30 auto has_destroy_imp(H&&, long) -> std::false_type;
31 
32 template <class H>
has_destroy()33 constexpr bool has_destroy() {
34   return decltype(has_destroy_imp(std::declval<H>(), 0))::value;
35 }
36 
37 template <class Promise>
do_test(std::coroutine_handle<Promise> && H)38 void do_test(std::coroutine_handle<Promise>&& H) {
39   using HType = std::coroutine_handle<Promise>;
40   // FIXME Add a runtime test
41   {
42     ASSERT_SAME_TYPE(decltype(H.destroy()), void);
43     LIBCPP_ASSERT_NOT_NOEXCEPT(H.destroy());
44     static_assert(has_destroy<HType&>(), "");
45     static_assert(has_destroy<HType&&>(), "");
46   }
47   {
48     static_assert(has_destroy<HType const&>(), "");
49     static_assert(has_destroy<HType const&&>(), "");
50   }
51 }
52 
main(int,char **)53 int main(int, char**)
54 {
55   do_test(std::coroutine_handle<>{});
56   do_test(std::coroutine_handle<int>{});
57 
58   return 0;
59 }
60