| 1 |
#include <coroutine> |
| 2 |
/* Make sure that we correctly warn for unused co_await results. */ |
| 3 |
|
| 4 |
struct task |
| 5 |
{ |
| 6 |
struct promise_type |
| 7 |
{ |
| 8 |
std::suspend_never initial_suspend () noexcept; |
| 9 |
std::suspend_never final_suspend () noexcept; |
| 10 |
void return_void (); |
| 11 |
void unhandled_exception (); |
| 12 |
task get_return_object (); |
| 13 |
}; |
| 14 |
}; |
| 15 |
|
| 16 |
template<typename T> |
| 17 |
struct nodiscardable : std::suspend_never |
| 18 |
{ [[nodiscard]] T await_resume (); }; |
| 19 |
|
| 20 |
template<typename T> |
| 21 |
struct discardable : std::suspend_never |
| 22 |
{ T await_resume (); }; |
| 23 |
|
| 24 |
task |
| 25 |
thing () |
| 26 |
{ |
| 27 |
co_await nodiscardable<int&>{}; /* { dg-warning "attribute 'nodiscard'" } */ |
| 28 |
co_await nodiscardable<int>{}; /* { dg-warning "attribute 'nodiscard'" } */ |
| 29 |
|
| 30 |
(void) co_await nodiscardable<int&>{}; |
| 31 |
(void) co_await nodiscardable<int>{}; |
| 32 |
|
| 33 |
co_await discardable<int&>{}; |
| 34 |
co_await discardable<volatile int&>{}; |
| 35 |
/* { dg-warning "implicit dereference will not access" "" { target *-*-* } {.-1} } */ |
| 36 |
} |
| 37 |
|
| 38 |
template<typename> |
| 39 |
task |
| 40 |
other_thing () |
| 41 |
{ |
| 42 |
co_await nodiscardable<int&>{}; /* { dg-warning "attribute 'nodiscard'" } */ |
| 43 |
co_await nodiscardable<int>{}; /* { dg-warning "attribute 'nodiscard'" } */ |
| 44 |
|
| 45 |
(void) co_await nodiscardable<int&>{}; |
| 46 |
(void) co_await nodiscardable<int>{}; |
| 47 |
|
| 48 |
co_await discardable<int&>{}; |
| 49 |
co_await discardable<volatile int&>{}; |
| 50 |
/* { dg-warning "implicit dereference will not access" "" { target *-*-* } {.-1} } */ |
| 51 |
} |
| 52 |
|
| 53 |
void |
| 54 |
other_thing_caller () |
| 55 |
{ |
| 56 |
other_thing <int> (); |
| 57 |
} |
| 58 |
|
| 59 |
task |
| 60 |
yet_another_thing (auto) |
| 61 |
{ |
| 62 |
co_await nodiscardable<int&>{}; /* { dg-warning "attribute 'nodiscard'" } */ |
| 63 |
co_await nodiscardable<int>{}; /* { dg-warning "attribute 'nodiscard'" } */ |
| 64 |
|
| 65 |
(void) co_await nodiscardable<int&>{}; |
| 66 |
(void) co_await nodiscardable<int>{}; |
| 67 |
|
| 68 |
co_await discardable<int&>{}; |
| 69 |
co_await discardable<volatile int&>{}; |
| 70 |
/* { dg-warning "implicit dereference will not access" "" { target *-*-* } {.-1} } */ |
| 71 |
} |
| 72 |
|
| 73 |
void |
| 74 |
yet_another_thing_caller () |
| 75 |
{ |
| 76 |
yet_another_thing (1); |
| 77 |
} |