From 855c09221a679b38cbff0193b93c5c13a1c1a723 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Tue, 27 Mar 2018 03:33:06 +0000 Subject: [PATCH] [coroutines] Fix unused warning on result of co_yield. This patch follows up on r328602, which fixed the spurious unused result warning for `co_await`. llvm-svn: 328607 --- clang/lib/AST/Expr.cpp | 3 ++- clang/test/SemaCXX/coroutines.cpp | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 3cb0013c9bfa..57c8850ba912 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -2050,7 +2050,8 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc, return cast(this)->getResultExpr()-> isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); case CoawaitExprClass: - return cast(this)->getResumeExpr()-> + case CoyieldExprClass: + return cast(this)->getResumeExpr()-> isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx); case ChooseExprClass: return cast(this)->getChosenSubExpr()-> diff --git a/clang/test/SemaCXX/coroutines.cpp b/clang/test/SemaCXX/coroutines.cpp index 308e70e054ab..c09ca570636c 100644 --- a/clang/test/SemaCXX/coroutines.cpp +++ b/clang/test/SemaCXX/coroutines.cpp @@ -1338,7 +1338,6 @@ bad_coroutine_calls_with_no_matching_constructor(int, int) { } // namespace CoroHandleMemberFunctionTest - class awaitable_no_unused_warn { public: using handle_type = std::experimental::coroutine_handle<>; @@ -1357,7 +1356,25 @@ public: int await_resume() { return 1; } }; -void test_unused_warning() { +template +struct check_warning_promise { + coro get_return_object(); + Await initial_suspend(); + Await final_suspend(); + Await yield_value(int); + void return_void(); + void unhandled_exception(); +}; + + +coro> +test_no_unused_warning() { co_await awaitable_no_unused_warn(); - co_await awaitable_unused_warn(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + co_yield 42; +} + +coro> +test_unused_warning() { + co_await awaitable_unused_warn(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} + co_yield 42; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} }