[clang] [Clang] Warn about `[[noreturn]]` on coroutines (PR #127623)

via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 18 12:22:48 PST 2025


================
@@ -3910,8 +3910,13 @@ StmtResult Sema::BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
     FnRetType = FD->getReturnType();
     if (FD->hasAttrs())
       Attrs = &FD->getAttrs();
-    if (FD->isNoReturn())
-      Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr) << FD;
+    if (FD->isNoReturn()) {
+      const FunctionScopeInfo *Scope = getEnclosingFunction();
+      if (Scope && Scope->isCoroutine())
+        Diag(ReturnLoc, diag::warn_noreturn_coroutine) << FD;
+      else
+        Diag(ReturnLoc, diag::warn_noreturn_function_has_return_expr) << FD;
+    }
----------------
Sirraide wrote:

> The diagnostic for noreturn functions was there before (i.e. your suggested change would remove it)

It’s supposed to remove it iff the enclosing function is a coroutine. We should still emit noreturn warnings for regular functions.

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


More information about the cfe-commits mailing list