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 #include <coroutine>
12 #include <type_traits>
13
14 #include "test_macros.h"
15
16 template <class T, class = typename T::promise_type>
has_promise_type(int)17 constexpr bool has_promise_type(int) { return true; }
18 template <class>
has_promise_type(long)19 constexpr bool has_promise_type(long) { return false; }
20 template <class T>
has_promise_type()21 constexpr bool has_promise_type() { return has_promise_type<T>(0); }
22
23 struct A {
24 using promise_type = A*;
25 };
26
27 struct B {};
28 struct C {};
29 struct D {
30 private:
31 using promise_type = void;
32 };
33 struct E {};
34
35 template <>
36 struct std::coroutine_traits<A, int> {
37 using promise_type = int*;
38 };
39 template <class ...Args>
40 struct std::coroutine_traits<B, Args...> {
41 using promise_type = B*;
42 };
43 template <>
44 struct std::coroutine_traits<C> {
45 using promise_type = void;
46 };
47
48 template <class Expect, class T, class ...Args>
check_type()49 void check_type() {
50 using Traits = std::coroutine_traits<T, Args...>;
51 static_assert(has_promise_type<Traits>(), "");
52 static_assert(std::is_same<typename Traits::promise_type, Expect>::value, "");
53 }
54
55 template <class T, class ...Args>
check_no_type()56 void check_no_type() {
57 using Traits = std::coroutine_traits<T, Args...>;
58 static_assert(!has_promise_type<Traits>(), "");
59 }
60
main(int,char **)61 int main(int, char**)
62 {
63 {
64 check_type<A*, A>();
65 check_type<int*, A, int>();
66 check_type<B*, B>();
67 check_type<void, C>();
68 }
69 {
70 check_no_type<D>();
71 check_no_type<E>();
72 check_no_type<C, int>();
73 }
74
75 return 0;
76 }
77