[clang-tools-extra] [clang-tidy] Improve `bugprone-exception-escape`: add stacktrace of escaped exception (PR #134375)

Congcong Cai via cfe-commits cfe-commits at lists.llvm.org
Sun May 25 18:59:16 PDT 2025


================
@@ -80,13 +78,47 @@ void ExceptionEscapeCheck::check(const MatchFinder::MatchResult &Result) {
   if (!MatchedDecl)
     return;
 
-  if (Tracer.analyze(MatchedDecl).getBehaviour() ==
-      utils::ExceptionAnalyzer::State::Throwing)
-    // FIXME: We should provide more information about the exact location where
-    // the exception is thrown, maybe the full path the exception escapes
-    diag(MatchedDecl->getLocation(), "an exception may be thrown in function "
-                                     "%0 which should not throw exceptions")
-        << MatchedDecl;
+  const utils::ExceptionAnalyzer::ExceptionInfo Info =
+      Tracer.analyze(MatchedDecl);
+
+  if (Info.getBehaviour() != utils::ExceptionAnalyzer::State::Throwing) {
+    return;
+  }
----------------
HerrCai0907 wrote:

```suggestion
  if (Info.getBehaviour() != utils::ExceptionAnalyzer::State::Throwing)
    return;
```

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


More information about the cfe-commits mailing list