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