[clang-tools-extra] [clang-tidy] Add misc-forbid-non-virtual-base-dtor check (PR #183384)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 2 07:39:23 PST 2026


vbvictor wrote:

> There’s also a broader upstream fit question. clang-tidy intentionally hosts checks for different code styles (and some are even mutually conflicting), but the successful upstream checks usually map to something widely accepted in major style guides or to a well-scoped bug pattern with low noise. This rule doesn’t really seem enforced by any major C++ style guide in that form. It feels more like an “XY problem”: we want to catch polymorphic deletion with a non-virtual base destructor (the real bug), but we’re enforcing “avoid certain inheritance shapes” as a proxy. That proxy is where the false positives and design pressure come from.

There is one widely accepted guideline https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c35-a-base-class-destructor-should-be-either-public-and-virtual-or-protected-and-non-virtual.
I think it is pretty close to what we try to make here. I'm positive if we implement such check:

> Enforcement
A class with any virtual functions should have a destructor that is either public and virtual or else protected and non-virtual.
If a class inherits publicly from a base class, the base class should have a destructor that is either public and virtual or else protected and non-virtual.


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


More information about the cfe-commits mailing list