]> git.ipfire.org Git - thirdparty/gcc.git/commit
cp+coroutines: teach convert_to_void to diagnose discarded co_awaits
authorArsen Arsenović <arsen@aarsen.me>
Mon, 22 Jul 2024 13:49:20 +0000 (15:49 +0200)
committerArsen Arsenović <arsen@gcc.gnu.org>
Thu, 25 Jul 2024 14:44:38 +0000 (16:44 +0200)
commit2664c1bf83855b79d8c43772e71b87ed4f09c174
treea2369f9726d4d3b34a293660516df347655fc68e
parent1a37d6b732506f8c3f9e9452c9dc6a456f25397b
cp+coroutines: teach convert_to_void to diagnose discarded co_awaits

co_await expressions are nearly calls to Awaitable::await_resume, and,
as such, should inherit its nodiscard.  A discarded co_await expression
should, hence, act as if its call to await_resume was discarded.

This patch teaches convert_to_void how to discard 'through' a
CO_AWAIT_EXPR. When we discard a CO_AWAIT_EXPR, we can also just discard
the await_resume() call conveniently embedded within it.  This results
in a [[nodiscard]] diagnostic that the PR noted was missing.

gcc/cp/ChangeLog:

PR c++/110171
* coroutines.cc (co_await_get_resume_call): New function.
Returns the await_resume expression of a given co_await.
* cp-tree.h (co_await_get_resume_call): New function.
* cvt.cc (convert_to_void): Handle CO_AWAIT_EXPRs and call
maybe_warn_nodiscard on their resume exprs.

gcc/testsuite/ChangeLog:

PR c++/110171
* g++.dg/coroutines/pr110171-1.C: New test.
* g++.dg/coroutines/pr110171.C: New test.
gcc/cp/coroutines.cc
gcc/cp/cp-tree.h
gcc/cp/cvt.cc
gcc/testsuite/g++.dg/coroutines/pr110171-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/coroutines/pr110171.C [new file with mode: 0644]