]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++, coroutines: Improve diagnostics for awaiter/promise.
authorIain Sandoe <iain@sandoe.co.uk>
Thu, 29 May 2025 15:50:44 +0000 (16:50 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Tue, 29 Jul 2025 15:08:11 +0000 (16:08 +0100)
commita2328db215cea44c2b3ad57a533b900723f43c10
treefa2b0d68e5a935ab7ae4304ffc1a90a37eef706a
parenta94894ffd5ca5c607160f8fde8eccd60d681c108
c++, coroutines: Improve diagnostics for awaiter/promise.

At present, we can issue diagnostics about missing or malformed
awaiter or promise methods when we encounter their uses in the
body of a user's function.  We might then re-issue the same
diagnostics when processing the initial or final await expressions.

This change avoids such duplication, and also attempts to
identify issues with the initial or final expressions specifically
since diagnostics for those do not have any useful line number.

gcc/cp/ChangeLog:

* coroutines.cc (build_co_await): Identify diagnostics
for initial and final await expressions.
(cp_coroutine_transform::wrap_original_function_body): Do
not handle initial and final await expressions here ...
(cp_coroutine_transform::apply_transforms): ... handle them
here and avoid duplicate diagnostics.
* coroutines.h: Declare inital and final await expressions
in the transform class.  Save the function closing brace
location.

gcc/testsuite/ChangeLog:

* g++.dg/coroutines/coro1-missing-await-method.C: Adjust for
improved diagnostics.
* g++.dg/coroutines/coro-missing-final-suspend.C: Likewise.
* g++.dg/coroutines/pr104051.C: Move to...
* g++.dg/coroutines/pr104051-0.C: ...here.
* g++.dg/coroutines/pr104051-1.C: New test.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
(cherry picked from commit 4c014a9db521b24bd900eb9a6ac70988322a57da)
gcc/cp/coroutines.cc
gcc/cp/coroutines.h
gcc/testsuite/g++.dg/coroutines/coro-missing-final-suspend.C
gcc/testsuite/g++.dg/coroutines/coro1-missing-await-method.C
gcc/testsuite/g++.dg/coroutines/pr104051-0.C [moved from gcc/testsuite/g++.dg/coroutines/pr104051.C with 89% similarity]
gcc/testsuite/g++.dg/coroutines/pr104051-1.C [new file with mode: 0644]