1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 // UNSUPPORTED: c++98, c++03, c++11
12
13 #include <experimental/coroutine>
14 #include <type_traits>
15 #include <cassert>
16
17 #include "test_macros.h"
18
19 namespace coro = std::experimental;
20
21 using SuspendT = std::experimental::coroutines_v1::suspend_always;
22
23 TEST_SAFE_STATIC SuspendT safe_sa;
24 constexpr SuspendT constexpr_sa;
25
check_suspend_constexpr()26 constexpr bool check_suspend_constexpr() {
27 SuspendT s{};
28 const SuspendT scopy(s); ((void)scopy);
29 SuspendT smove(std::move(s)); ((void)smove);
30 s = scopy;
31 s = std::move(smove);
32 return true;
33 }
34
main()35 int main()
36 {
37 using H = coro::coroutine_handle<>;
38 using S = SuspendT;
39 H h{};
40 S s{};
41 S const& cs = s;
42 {
43 LIBCPP_STATIC_ASSERT(noexcept(s.await_ready()), "");
44 static_assert(std::is_same<decltype(s.await_ready()), bool>::value, "");
45 assert(s.await_ready() == false);
46 assert(cs.await_ready() == false);
47 }
48 {
49 LIBCPP_STATIC_ASSERT(noexcept(s.await_suspend(h)), "");
50 static_assert(std::is_same<decltype(s.await_suspend(h)), void>::value, "");
51 s.await_suspend(h);
52 cs.await_suspend(h);
53 }
54 {
55 LIBCPP_STATIC_ASSERT(noexcept(s.await_resume()), "");
56 static_assert(std::is_same<decltype(s.await_resume()), void>::value, "");
57 s.await_resume();
58 cs.await_resume();
59 }
60 {
61 static_assert(std::is_nothrow_default_constructible<S>::value, "");
62 static_assert(std::is_nothrow_copy_constructible<S>::value, "");
63 static_assert(std::is_nothrow_move_constructible<S>::value, "");
64 static_assert(std::is_nothrow_copy_assignable<S>::value, "");
65 static_assert(std::is_nothrow_move_assignable<S>::value, "");
66 static_assert(std::is_trivially_copyable<S>::value, "");
67 static_assert(check_suspend_constexpr(), "");
68 }
69 {
70 // suppress unused warnings for the global constexpr test variable
71 ((void)constexpr_sa);
72 }
73 }
74