================
@@ -0,0 +1,52 @@
+.. 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()
+
+The following patterns are safe and will **not** trigger a warning:
+
+.. code-block:: c++
+
+  // safe: base has a virtual destructor
----------------
EugeneZelenko wrote:

is it really necessary to repeat `safe:`? Same below.

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

Reply via email to