# C++: warning: deleting object of polymorphic class type 'Base' which has non-virtual destructor might cause undefined behavior

**Code:** `non-virtual destructor` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang

A base class with virtual functions is deleted through a base pointer but its destructor is not virtual.

## Meaning

Only the base destructor runs, so the derived object's members leak and the behaviour is undefined. Make the base destructor virtual.

## Common causes

- Base class has virtual methods but a non-virtual destructor
- Deleting via `Base*`
- `std::unique_ptr<Base>` of a derived object

## Quick fix

1. Declare `virtual ~Base() = default;`
2. Use `-Wnon-virtual-dtor` to catch it early

## Detailed fix by platform

### GCC / Clang

1. Add `-Wall -Wnon-virtual-dtor -Wdelete-non-virtual-dtor`

## Code examples

### virtual destructor

```cpp
struct Base { virtual void run(); };         // warning when deleted via Base*
struct Fixed { virtual ~Fixed() = default; virtual void run(); };
```

## How to diagnose

1. **Virtual** — Any virtual function?
2. **Delete** — Deleted through base pointer?
3. **Dtor** — Virtual?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/non-virtual-destructor)
