77 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -std=c++20 -fsyntax-only -verify -Wunreachable-code2 3#include "Inputs/std-coroutine.h"4 5extern void abort(void) __attribute__((__noreturn__));6 7struct task {8 struct promise_type {9 std::suspend_always initial_suspend();10 std::suspend_always final_suspend() noexcept;11 void return_void();12 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 };21 auto await_transform(const int& x) { return Awaiter{}; }22 };23};24 25task test1() {26 abort();27 co_yield 1;28}29 30task test2() {31 abort();32 1; // expected-warning {{code will never be executed}}33 co_yield 1;34}35 36task test3() {37 abort();38 co_return;39}40 41task test4() {42 abort();43 1; // expected-warning {{code will never be executed}}44 co_return;45}46 47task test5() {48 abort();49 co_await 1;50}51 52task test6() {53 abort();54 1; // expected-warning {{code will never be executed}}55 co_await 3;56}57 58task test7() {59 // coroutine statements are not considered unreachable.60 co_await 1;61 abort();62 co_await 2;63}64 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 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