================
@@ -0,0 +1,48 @@
+.. title:: clang-tidy - misc-forbid-non-virtual-base-dtor
+
+misc-forbid-non-virtual-base-dtor
+=================================
+
+Warns when a class or struct publicly inherits from a base class or struct
+whose destructor is neither virtual nor protected, and the derived class adds
+data members. This pattern causes resource leaks when the derived object is
+deleted through a base class pointer, because the derived destructor is never
+called.
+
+Examples
+--------
+
+The following code will trigger a warning:
+
+.. code-block:: c++
+
+ class Base {}; // non-virtual destructor
+
+ class Derived : public Base { // warning: class 'Derived' inherits from
+ int data; // 'Base' which has a non-virtual destructor
+ };
+
+ Base *b = new Derived();
+ delete b; // leaks Derived::data —> Base::~Base() is called, not ~Derived()
----------------
zeyi2 wrote:
Nit pick: could we use the ascii `-` instead of em-dash?
https://github.com/llvm/llvm-project/pull/183384
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits