1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -std=c++20 -fsyntax-only -verify -Wunreachable-code 2 3 #include "Inputs/std-coroutine.h" 4 5 extern void abort(void) __attribute__((__noreturn__)); 6 7 struct task { 8 struct promise_type { 9 std::suspend_always initial_suspend(); 10 std::suspend_always final_suspend() noexcept; 11 void return_void(); yield_valuetask::promise_type12 std::suspend_always yield_value(int) { return {}; } 13 task get_return_object(); 14 void unhandled_exception(); 15 16 struct Awaiter { 17 bool await_ready(); 18 void await_suspend(auto); 19 int await_resume(); 20 }; await_transformtask::promise_type21 auto await_transform(const int& x) { return Awaiter{}; } 22 }; 23 }; 24 test1()25task test1() { 26 abort(); 27 co_yield 1; 28 } 29 test2()30task test2() { 31 abort(); 32 1; // expected-warning {{code will never be executed}} 33 co_yield 1; 34 } 35 test3()36task test3() { 37 abort(); 38 co_return; 39 } 40 test4()41task test4() { 42 abort(); 43 1; // expected-warning {{code will never be executed}} 44 co_return; 45 } 46 test5()47task test5() { 48 abort(); 49 co_await 1; 50 } 51 test6()52task test6() { 53 abort(); 54 1; // expected-warning {{code will never be executed}} 55 co_await 3; 56 } 57 test7()58task test7() { 59 // coroutine statements are not considered unreachable. 60 co_await 1; 61 abort(); 62 co_await 2; 63 } 64 test8()65task test8() { 66 // coroutine statements are not considered unreachable. 67 abort(); 68 co_return; 69 1 + 1; // expected-warning {{code will never be executed}} 70 } 71 test9()72task test9() { 73 abort(); 74 // This warning is emitted on the declaration itself, rather the coroutine substmt. 75 int x = co_await 1; // expected-warning {{code will never be executed}} 76 } 77