non-virtual destructor C/C++ Origin: Application & API OSI layer 7 · Application Last updated 28 Nov 2026

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.

Exact message you may see non-virtual destructordeleting object of polymorphic class typehas virtual functions and accessible non-virtual destructor
Seen on: C/C++ GCC Clang

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?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

C2259 — MSVC: error C2259: 'X': cannot instantiate abstract class (C/C++)C2259call of overloaded is ambiguous — C++: error: call of overloaded 'f(int)' is ambiguous (C/C++)call of overloaded is…cannot declare variable to be of abstract type — C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions) (C/C++)cannot declare variab…double free or corruption — C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped) (C/C++)double free or corrup…marked override but does not override — C++: error: 'void D::f()' marked 'override', but does not override (C/C++)marked override but d…pure virtual method called — C++: pure virtual method called — terminate called without an active exception (C/C++)pure virtual method c…reference to is ambiguous — C++: error: reference to 'X' is ambiguous (using namespace std conflicts) (C/C++)reference to is ambig…undefined reference to vtable — C++: undefined reference to `vtable for X' — virtual function not defined (C/C++)undefined reference t…non-virtu…

Explore the map of this error Full error map →

🧠 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.