| 1 |
// { dg-additional-options "-fsyntax-only " } |
| 2 |
#if !__has_include(<coroutine>) \ |
| 3 |
&& __has_include(<experimental/coroutine>) // for __clang__ |
| 4 |
#include <experimental/coroutine> |
| 5 |
namespace std { |
| 6 |
using namespace std::experimental; |
| 7 |
} |
| 8 |
#else |
| 9 |
#include <coroutine> |
| 10 |
#endif |
| 11 |
|
| 12 |
struct Task |
| 13 |
{ |
| 14 |
struct promise_type |
| 15 |
{ |
| 16 |
void return_void() const noexcept {} |
| 17 |
|
| 18 |
void* operator new(std::size_t, auto &&...args) noexcept |
| 19 |
{ |
| 20 |
static_assert(sizeof...(args) > 0); |
| 21 |
static_assert(sizeof...(args) == 2); |
| 22 |
|
| 23 |
return nullptr; |
| 24 |
} |
| 25 |
|
| 26 |
void operator delete(void *, std::size_t) noexcept |
| 27 |
{ |
| 28 |
} |
| 29 |
|
| 30 |
static Task get_return_object_on_allocation_failure() noexcept |
| 31 |
{ |
| 32 |
return {}; |
| 33 |
} |
| 34 |
|
| 35 |
Task get_return_object() noexcept |
| 36 |
{ |
| 37 |
return Task{ *this }; |
| 38 |
} |
| 39 |
|
| 40 |
std::suspend_always initial_suspend() noexcept |
| 41 |
{ |
| 42 |
return {}; |
| 43 |
} |
| 44 |
|
| 45 |
std::suspend_always final_suspend() noexcept |
| 46 |
{ |
| 47 |
return {}; |
| 48 |
} |
| 49 |
|
| 50 |
void unhandled_exception() noexcept {} |
| 51 |
}; |
| 52 |
|
| 53 |
using promise_handle = std::coroutine_handle<promise_type>; |
| 54 |
|
| 55 |
Task() = default; |
| 56 |
Task(promise_type & promise) noexcept |
| 57 |
: m_handle{ promise_handle::from_promise(promise) } |
| 58 |
{} |
| 59 |
|
| 60 |
~Task() |
| 61 |
{ |
| 62 |
if (m_handle.address()) { m_handle.destroy(); } |
| 63 |
} |
| 64 |
|
| 65 |
promise_handle m_handle{}; |
| 66 |
}; |
| 67 |
|
| 68 |
|
| 69 |
Task Foo(auto && ... args) noexcept |
| 70 |
{ |
| 71 |
co_return; |
| 72 |
} |
| 73 |
|
| 74 |
int main() |
| 75 |
{ |
| 76 |
int v; |
| 77 |
Foo(v, 2134); |
| 78 |
} |