[clang] [clang][analyzer] Don't warn about virtual calls in final class destructors (PR #178654)
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 7 09:24:34 PST 2026
================
@@ -123,6 +123,21 @@ void VirtualCallChecker::checkPreCall(const CallEvent &Call,
if (!ObState)
return;
+ // If we're directly inside the constructor/destructor of a final class,
+ // virtual dispatch is safe because there can be no derived classes.
+ // We only suppress when directly in the ctor/dtor, not in helper functions
+ // (which could be called from non-final classes), and not in base class
+ // ctors/dtors (which have broken vtables even when constructing/destroying
+ // a final derived class).
----------------
haoNoQ wrote:
```suggestion
// We only suppress when directly in the derived class ctor/dtor and not in
// base class ctors/dtors which have broken vtables even when constructing
// or destroying a final derived class.
// FIXME: We only suppress when directly in the ctor/dtor, not in arbitrary
// helper functions that may be defined anywhere and called through an
// arbitrary call stack. C.getLocationContext() does not always represent
// the stack frame we should be looking at, which can incorrectly swing
// this check in either direction.
// FIXME: The method MD may be final even when the class isn't.
```
https://github.com/llvm/llvm-project/pull/178654
More information about the cfe-commits
mailing list