xref: /llvm-project/clang/test/SemaCXX/cxx2b-deducing-this-coro.cpp (revision af4751738db89a142a8880c782d12d4201b222a8)
1 // RUN: %clang_cc1 -std=c++2b %s -fsyntax-only -verify
2 
3 #include "Inputs/std-coroutine.h"
4 
5 struct S;
6 template <typename T>
7 class coro_test {
8 public:
9     struct promise_type;
10     using handle = std::coroutine_handle<promise_type>;
11 	struct promise_type {
12         promise_type(const promise_type&) = delete; // #copy-ctr
13         promise_type(T);  // #candidate
14         coro_test get_return_object();
15         std::suspend_never initial_suspend();
16 	    std::suspend_never final_suspend() noexcept;
17 	    void return_void();
18         void unhandled_exception();
19 
20 
21         template<typename Arg, typename... Args>
22         void* operator new(decltype(0zu) sz, Arg&&, Args&... args) {
23             static_assert(!__is_same(__decay(Arg), S), "Ok"); // expected-error 2{{Ok}}
24         }
25 
26     };
27 private:
28 	handle h;
29 };
30 
31 
32 template <typename Ret, typename... P>
33 struct std::coroutine_traits<coro_test<S&>, Ret, P...> {
34   using promise_type = coro_test<S&>::promise_type;
35   static_assert(!__is_same(Ret, S&), "Ok"); // expected-error{{static assertion failed due to requirement '!__is_same(S &, S &)': Ok}}
36 };
37 
38 
39 struct S {
40 
okS41     coro_test<S&> ok(this S&, int) {
42         co_return; // expected-note {{in instantiation}}
43     }
44 
ok2S45     coro_test<const S&> ok2(this const S&) { // expected-note {{in instantiation}}
46         co_return;
47     }
48 
koS49     coro_test<int> ko(this const S&) {  // expected-error {{no matching constructor for initialization of 'std::coroutine_traits<coro_test<int>, const S &>::promise_type'}} \
50                                         // expected-note {{in instantiation}} \
51                                        // FIXME: the message below is unhelpful but this is pre-existing
52                                        // expected-note@#candidate {{candidate constructor not viable: requires 1 argument, but 0 were provided}} \
53                                        // expected-note@#copy-ctr  {{candidate constructor not viable}}
54         co_return;
55     }
56 
57 };
58