r328607 - [coroutines] Fix unused warning on result of co_yield.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 26 20:33:06 PDT 2018
Author: ericwf
Date: Mon Mar 26 20:33:06 2018
New Revision: 328607
URL: http://llvm.org/viewvc/llvm-project?rev=328607&view=rev
Log:
[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`.
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/test/SemaCXX/coroutines.cpp
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=328607&r1=328606&r2=328607&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Mar 26 20:33:06 2018
@@ -2050,7 +2050,8 @@ bool Expr::isUnusedResultAWarning(const
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()->
Modified: cfe/trunk/test/SemaCXX/coroutines.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/coroutines.cpp?rev=328607&r1=328606&r2=328607&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/coroutines.cpp (original)
+++ cfe/trunk/test/SemaCXX/coroutines.cpp Mon Mar 26 20:33:06 2018
@@ -1338,7 +1338,6 @@ bad_coroutine_calls_with_no_matching_con
} // 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}}
}
More information about the cfe-commits
mailing list