[clang-tools-extra] [clang-tidy] Add options to throw unannotated functions in `bugprone-exception-escape` (PR #168324)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 21 06:21:25 PST 2025


================
@@ -103,22 +109,35 @@ void ExceptionEscapeCheck::check(const MatchFinder::MatchResult &Result) {
   const utils::ExceptionAnalyzer::ExceptionInfo Info =
       Tracer.analyze(MatchedDecl);
 
-  if (Info.getBehaviour() != utils::ExceptionAnalyzer::State::Throwing)
+  const auto Behaviour = Info.getBehaviour();
+  const bool IsThrowing =
+      Behaviour == utils::ExceptionAnalyzer::State::Throwing;
+  const bool IsUnknown = Behaviour == utils::ExceptionAnalyzer::State::Unknown;
+
+  const bool ReportUnknown =
+      IsUnknown &&
+      ((KnownUnannotatedAsThrowing && Info.hasUnknownFromKnownUnannotated()) ||
+       (UnknownAsThrowing && Info.hasUnknownFromMissingDefinition()));
+
+  if (!(IsThrowing || ReportUnknown))
     return;
 
-  diag(MatchedDecl->getLocation(), "an exception may be thrown in function "
-                                   "%0 which should not throw exceptions")
+  diag(MatchedDecl->getLocation(), "an exception may be thrown in function %0 "
+                                   "which should not throw exceptions")
       << MatchedDecl;
 
+  if (Info.getExceptions().empty())
+    return;
+
   const auto &[ThrowType, ThrowInfo] = *Info.getExceptions().begin();
 
   if (ThrowInfo.Loc.isInvalid())
     return;
 
   const utils::ExceptionAnalyzer::CallStack &Stack = ThrowInfo.Stack;
   diag(ThrowInfo.Loc,
-       "frame #0: unhandled exception of type %0 may be thrown in function %1 "
-       "here",
+       "frame #0: unhandled exception of type %0 may be thrown in function "
+       "%1 here",
----------------
vbvictor wrote:

Same seems unrelated

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


More information about the cfe-commits mailing list