[clang] Surface error for plain return statement in coroutine earlier (PR #100985)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 29 02:21:37 PDT 2024
================
@@ -1120,7 +1120,7 @@ void Sema::CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body) {
// [stmt.return.coroutine]p1:
// A coroutine shall not enclose a return statement ([stmt.return]).
- if (Fn->FirstReturnLoc.isValid()) {
+ if (Fn->FirstReturnLoc.isValid() && Fn->FirstReturnLoc < Fn->FirstCoroutineStmtLoc) {
----------------
ilya-biryukov wrote:
We now have some asymmetry between the way we handle errors for `co_await` after `return` and for `return` after `co_await`. (Also for other coroutine keywords, but I'll keep only mentioning `co_await` for simplicity).
I think we could get rid of that by moving this code into the function that handles `co_await`. It can check `FirstReturnLoc.isValid()` and issue and error in the same way as `return` checks for `FirstCoroutineStmtLoc.isValid()` (which is the implementation of `Fn->isCoroutine()`) and issues an error.
https://github.com/llvm/llvm-project/pull/100985
More information about the cfe-commits
mailing list