Debian Codegraph @

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

raw
1 // { dg-additional-options "-fsyntax-only" }
2 // PR116775
3 #include <coroutine>
4 #ifndef OUTPUT
5 # define PRINT(X)
6 # define PRINTF(...)
7 #else
8 #include <cstdio>
9 # define PRINT(X) puts(X)
10 # define PRINTF(...) printf(__VA_ARGS__)
11 #endif
12
13 struct awaitable {
14 awaitable(int n) : delay{n} {}
15
16 constexpr bool await_ready() const noexcept { return false; }
17 auto await_suspend(std::coroutine_handle<> h) const {
18 __builtin_trap ();
19 return false;
20 }
21 int await_resume() const noexcept {
22 return delay;
23 }
24
25 int delay;
26 };
27
28 struct Task {
29 struct promise_type {
30 promise_type() = default;
31 Task get_return_object() { return {}; }
32 std::suspend_never initial_suspend() { return {}; }
33 std::suspend_always final_suspend() noexcept { return {}; }
34 void unhandled_exception() {}
35 void return_void () {}
36 awaitable yield_value (int v) { return {v}; }
37 };
38 };
39
40 Task foo() noexcept {
41 if (__builtin_constant_p (true ? 1 : co_await awaitable{10}))
42 PRINT ("const OK");
43 else
44 {
45 PRINT ("failed : should be const");
46 __builtin_abort ();
47 }
48 if (__builtin_constant_p (false ? 1 : co_await awaitable{15}))
49 {
50 PRINT ("failed : should not be const");
51 __builtin_abort ();
52 }
53 else
54 PRINT ("not const, OK");
55 if (__builtin_constant_p (5 == (co_yield 42)))
56 {
57 PRINT ("failed : should not be const");
58 __builtin_abort ();
59 }
60 else
61 PRINT ("not const, OK");
62 co_return;
63 }
64
65 //call foo
66 int main() {
67 foo();
68 }