================
@@ -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()
+
+The following patterns are safe and will **not** trigger a warning:
+
+.. code-block:: c++
+
+ class Base1 {
+ public:
+ virtual ~Base1() {}
+ };
+ class Derived1 : public Base1 { int data; };
+
+ class Base2 {
+ protected:
+ ~Base2() {}
+ };
+ class Derived2 : public Base2 { int data; };
+
+ class Base3 {};
+ class Derived3 : public Base3 {}; // OK
----------------
EugeneZelenko wrote:
```suggestion
class Derived3 : public Base3 {};
```
All cases in this section are OK.
https://github.com/llvm/llvm-project/pull/183384
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits