1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify -std=c++20 -I%S/Inputs -Wno-unused -Wno-uninitialized -Wunsequenced %s
3 // expected-no-diagnostics
5 #include "std-coroutine.h"
7 typedef __PTRDIFF_TYPE__
ptrdiff_t;
14 Task
<T
> get_return_object() noexcept
;
15 suspend_always
initial_suspend() noexcept
;
16 suspend_always
final_suspend() noexcept
;
18 void unhandled_exception();
19 auto yield_value(Task
<T
>) noexcept
{ return final_suspend(); }
21 bool await_ready() noexcept
{ return false; }
22 void await_suspend(coroutine_handle
<>) noexcept
{}
29 Task
<void> get_return_object() noexcept
;
30 suspend_always
initial_suspend() noexcept
;
31 suspend_always
final_suspend() noexcept
;
32 void return_void() noexcept
;
33 void unhandled_exception() noexcept
;
34 auto yield_value(Task
<void>) noexcept
{ return final_suspend(); }
36 bool await_ready() noexcept
{ return false; }
37 void await_suspend(coroutine_handle
<>) noexcept
{}
38 void await_resume() noexcept
{}
46 auto get_return_object() { return generator
{*this}; }
47 auto initial_suspend() { return suspend_never
{}; }
48 auto final_suspend() noexcept
{ return suspend_always
{}; }
49 void unhandled_exception() {}
52 auto yield_value(T value
)
54 value_
= std::move(value
);
55 return suspend_always
{};
61 using Handle
= coroutine_handle
<Promise
>;
66 using iterator_category
= input_iterator_tag
;
68 using difference_type
= ptrdiff_t;
69 using reference
= T
&;
70 using const_reference
= const T
&;
73 iterator
&operator++()
78 const_reference
&operator*() const { return h_
.promise().value_
; }
79 bool operator!=(sentinel
) { return !h_
.done(); }
84 explicit generator(Promise
&p
) : h_(Handle::from_promise(p
)) {}
87 using promise_type
= Promise
;
88 auto begin() { return iterator
{h_
}; }
89 auto end() { return sentinel
{}; }
93 co_await (i
= 0, std::suspend_always
{});
96 generator
<int> range(int start
, int end
)
102 Task
<int> go(int const& val
);
103 Task
<int> go1(int x
) {
104 co_return co_await
go(++x
);