[clang] [Clang] Warn about `[[noreturn]]` on coroutines (PR #127623)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 18 12:32:41 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;
+ }
----------------
Nerixyz wrote:
> It’s supposed to remove it iff the enclosing function is a coroutine.
Sorry, I missed the `!`.
> I still think it makes more sense to diagnose this when the FunctionDecl is created rather than when we try and return from it.
`CheckCompletedCoroutineBody` sounds like a good place to do that.
https://github.com/llvm/llvm-project/pull/127623
More information about the cfe-commits
mailing list