diff options
author | Arsen Arsenović <arsen@aarsen.me> | 2024-07-22 15:49:20 +0200 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2024-07-28 19:05:57 +0200 |
commit | f3131a07e5095ddb07adbd75ddba546a5e9bcbde (patch) | |
tree | a052a9c75d8c2597100a35e958f01a9d1363ecb2 /libcpp | |
parent | 3109e8c991762031b108ae2a022472b989cbb465 (diff) | |
download | gcc-f3131a07e5095ddb07adbd75ddba546a5e9bcbde.zip gcc-f3131a07e5095ddb07adbd75ddba546a5e9bcbde.tar.gz gcc-f3131a07e5095ddb07adbd75ddba546a5e9bcbde.tar.bz2 |
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.
Diffstat (limited to 'libcpp')
0 files changed, 0 insertions, 0 deletions