[clang] [Clang] Warn about `[[noreturn]]` on coroutines (PR #127623)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 18 12:27:12 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:
Also, looking at the AST, I think the only way for us to end up in `BuildReturnStmt` in a coroutine is for the `ReturnStmt` that the compiler implicitly generates for the call to `get_return_object()` since `return` is disallowed in coroutines; I don’t think we really care to diagnose that (because seriously, if e.g. `get_return_object()` is `noreturn`, then witw is the user trying to accomplish with that...)
https://github.com/llvm/llvm-project/pull/127623
More information about the cfe-commits
mailing list