[clang] Surface error for plain return statement in coroutine earlier (PR #100985)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 1 02:34:50 PDT 2024


================
@@ -684,6 +684,18 @@ bool Sema::checkFinalSuspendNoThrow(const Stmt *FinalSuspend) {
   return ThrowingDecls.empty();
 }
 
+// [stmt.return.coroutine]p1:
+//   A coroutine shall not enclose a return statement ([stmt.return]).
+static void checkReturnStmtInCoroutine(Sema &S, FunctionScopeInfo *FSI) {
+  if (FSI && FSI->FirstReturnLoc.isValid()) {
+      assert(FSI->FirstCoroutineStmtLoc.isValid() &&
----------------
ilya-biryukov wrote:

NIT: we could move this assertion to the start of the function. As the name implies, the `checkReturnStmtInCoroutine` can only be called on coroutines, so validating this invariant is useful even if we don't report any diagnostics.

https://github.com/llvm/llvm-project/pull/100985


More information about the cfe-commits mailing list