Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/assume.C

raw
1 // { dg-additional-options "-fsyntax-only -Wattributes" }
2
3 #include <coroutine>
4
5 struct awaitable {
6 awaitable (int n) : delay{n} {}
7
8 constexpr bool await_ready () const noexcept { return false; }
9 auto await_suspend (std::coroutine_handle<> h) const {
10 __builtin_abort ();
11 return false;
12 }
13 int await_resume() const noexcept {
14 return delay;
15 }
16
17 int delay;
18 };
19
20 struct Task {
21 struct promise_type {
22 promise_type() = default;
23 Task get_return_object() { return {}; }
24 std::suspend_never initial_suspend() { return {}; }
25 std::suspend_always final_suspend() noexcept { return {}; }
26 void unhandled_exception() {}
27 void return_void () {}
28 awaitable yield_value (int v) { return {v}; }
29 };
30 };
31
32 int h () { return 5; }
33
34 Task foo() noexcept {
35 int x = 5;
36 [[assume (x == 5)]];
37 [[assume (co_await awaitable{10})]]; // { dg-warning {assumption ignored because it contains an await-expression} }
38 [[assume ((h(),co_await awaitable{11}))]]; // { dg-warning {assumption ignored because it contains an await-expression} }
39 co_return;
40 }