[clang] [clang] [Sema] Suggest [[noreturn]] for void functions that always throw (PR #146234)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 30 06:52:22 PDT 2025


================
@@ -1979,6 +1979,9 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) {
   if (!FD->hasAttr<NoReturnAttr>() && !FD->hasAttr<InferredNoReturnAttr>() &&
       isKnownToAlwaysThrow(FD)) {
     NonConstFD->addAttr(InferredNoReturnAttr::CreateImplicit(S.Context));
+
+    // Emit a diagnostic suggesting the function being marked [[noreturn]].
+    S.Diag(FD->getLocation(), diag::warn_suggest_noreturn_function) << 0 << FD;
----------------
erichkeane wrote:

```suggestion
    S.Diag(FD->getLocation(), diag::warn_suggest_noreturn_function) << 0 << FD;
```

We need some comment saying what `0` means here.  Typically we do something like: `/*THING_THIS_SELECTS=*/0` here.

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


More information about the cfe-commits mailing list