]> granicus.if.org Git - clang/commitdiff
[coroutines] Fix unused warning on result of co_yield.
authorEric Fiselier <eric@efcs.ca>
Tue, 27 Mar 2018 03:33:06 +0000 (03:33 +0000)
committerEric Fiselier <eric@efcs.ca>
Tue, 27 Mar 2018 03:33:06 +0000 (03:33 +0000)
This patch follows up on r328602, which fixed the spurious unused
result warning for `co_await`.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328607 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/SemaCXX/coroutines.cpp

index 3cb0013c9bfacb293f50bf7bdb6becdda7d742b4..57c8850ba912e4a68d038b4d80aa79b6b5405400 100644 (file)
@@ -2050,7 +2050,8 @@ bool Expr::isUnusedResultAWarning(const Expr *&WarnE, SourceLocation &Loc,
     return cast<GenericSelectionExpr>(this)->getResultExpr()->
       isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
   case CoawaitExprClass:
-    return cast<CoawaitExpr>(this)->getResumeExpr()->
+  case CoyieldExprClass:
+    return cast<CoroutineSuspendExpr>(this)->getResumeExpr()->
       isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
   case ChooseExprClass:
     return cast<ChooseExpr>(this)->getChosenSubExpr()->
index 308e70e054aba89c85de0f7b5b81541e056c0e56..c09ca570636c3de6ace4513322f1ed1a4080dd44 100644 (file)
@@ -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 <class Await>
+struct check_warning_promise {
+  coro<check_warning_promise> get_return_object();
+  Await initial_suspend();
+  Await final_suspend();
+  Await yield_value(int);
+  void return_void();
+  void unhandled_exception();
+};
+
+
+coro<check_warning_promise<awaitable_no_unused_warn>>
+test_no_unused_warning() {
   co_await awaitable_no_unused_warn();
+  co_yield 42;
+}
+
+coro<check_warning_promise<awaitable_unused_warn>>
+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}}
 }