[clang] [analyzer] Confidently inline final methods (PR #224070)

Donát Nagy via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 18 22:08:30 PDT 2026


================
@@ -822,6 +830,10 @@ RuntimeDefinition CXXInstanceCall::getRuntimeDefinition() const {
     return {};
   }
 
+  // A final method cannot be overriden in a subclass.
+  if (Result->hasAttr<FinalAttr>() || Result->getParent()->hasAttr<FinalAttr>())
----------------
NagyDonat wrote:

> This means, by extension, that even if a class is in an anon namespace, that does not mean that there can't be other classes inheriting from it and overriding its non-final methods.

This is not what @earnol claimed – he only claimed that there can't be other classes _in other TUs_ inheriting from it, and _if we don't see an inheriting class in the current TU_ then we can inline its methods. Of course, it is possible to override methods of an anonymous class – but any such overrides are visible in the current TU.

My example tried to demonstrate that even if the anonymous namespace is in the header and there is a class in another TU that _seems to derive from the anonymous class_, it is in fact derived from a distinct class declared by the same code text in the anonymous namespace of a different TU.

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


More information about the cfe-commits mailing list