C++: warning: deleting object of polymorphic class type 'Base' which has non-virtual destructor might cause undefined behavior
A base class with virtual functions is deleted through a base pointer but its destructor is not virtual.
non-virtual destructordeleting object of polymorphic class typehas virtual functions and accessible non-virtual destructor 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
- Declare
virtual ~Base() = default; - Use
-Wnon-virtual-dtorto catch it early
Detailed fix by platform
GCC / Clang
- Add
-Wall -Wnon-virtual-dtor -Wdelete-non-virtual-dtor
Code examples
virtual destructor
struct Base { virtual void run(); }; // warning when deleted via Base*
struct Fixed { virtual ~Fixed() = default; virtual void run(); };How to diagnose
- Virtual — Any virtual function?
- Delete — Deleted through base pointer?
- Dtor — Virtual?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in C/C++
- Bus error C/C++: Bus error (core dumped) — SIGBUS from misaligned access or a bad memory-mapped file
- AddressSanitizer: heap-use-after-free C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 28 Nov 2026