[clang] [clang][analyzer] Don't warn about virtual calls in final class destructors (PR #178654)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 29 06:13:54 PST 2026


================
@@ -123,6 +123,13 @@ void VirtualCallChecker::checkPreCall(const CallEvent &Call,
   if (!ObState)
     return;
 
+  // If the class whose constructor/destructor we're in is marked final,
+  // virtual dispatch is safe because there can be no derived classes.
+  const auto *LCtx = C.getLocationContext();
+  const auto *CurMethod = dyn_cast_or_null<CXXMethodDecl>(LCtx->getDecl());
+  if (CurMethod && CurMethod->getParent()->hasAttr<FinalAttr>())
----------------
steakhal wrote:

Shouldn't this be just this:

```suggestion
  if (MD->getParent()->hasAttr<FinalAttr>())
```

Or maybe even better:
```suggestion
  if (MD->getParent()->isEffectivelyFinal())
```

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


More information about the cfe-commits mailing list