[PATCH] D35796: [analyzer] Misused polymorphic object checker

Reka Kovacs via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 26 02:10:25 PDT 2017


rnkovacs added a comment.

In https://reviews.llvm.org/D35796#819965, @NoQ wrote:

> It seems that this check is more powerful because it works by knowing the dynamic type of the object. However, i still suspect that `-Wnon-virtual-dtor` (the other one, without `delete-`, that simply asks to make the destructor of polymorphic classes virtual) covers most practical cases. The only thing i see not covered by `-Wnon-virtual-dtor` but covered by this checker is the situation when the destructor is private. Reka, would you confirm our understanding?


You're right, the flag covers many cases, but there are some common exceptions. E.g. deleting a polymorphic object without a virtual destructor might not be a problem if it's referenced by its precise type. The checker is aware of this. It looks for object deletions, checks their dynamic and static types, and only warns if an object is deleted through a base pointer (with no virtual destructor).

I added a slightly more sophisticated test case for the private destructor situation, I'm wondering whether you meant something like that.


https://reviews.llvm.org/D35796





More information about the cfe-commits mailing list