================
@@ -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>())
----------------
steakhal wrote:

@NagyDonat This is not what I intended to convey.

I built a counter-example for an anonymous (non-final) class of which its 
virtual method get overridden. 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. Consequently, if we 
see a callexpr of `Der::fun` - we can't assume that it will resolve to 
`Der::fun` at runtime. This is all I'm saying. There is no UB here, nor 
dynamic_casts.

Speaking of your example, that code AFAIK is standard compliant and the dynamic 
cast always fails - as you expected.

https://github.com/llvm/llvm-project/pull/224070
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to