C++: pure virtual method called, terminate called without an active exception
A pure virtual function was called through an object whose derived part does not exist at that moment. It almost always means a virtual call from a base class constructor or destructor, where the object is only the base type, or a call on an object that another thread has already started destroying. The second case makes it intermittent and hard to reproduce.
Quick fix
Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.
// Wrong: during ~Base the object is only a Base, so run() is pure
struct Base {
virtual void run() = 0;
~Base() { stop(); } // stop() calls run(): pure virtual call
};
// Fix: stop from the derived destructor, or before destruction
struct Worker : Base {
~Worker() override { stop(); }
};
// Threads: join before the object is destroyed
// worker_thread.join(); then let the object go out of scope
# Find the frame that made the call
gdb -ex run -ex bt --args ./app
# Or catch the destroyed-object case with ASan
g++ -g -fsanitize=address main.cpp -o app
How to diagnose C++ errors
C++ errors fall into two very different worlds. Compile and link errors (undefined reference, multiple definition, template substitution failure) are deterministic and are almost always about declarations, the One Definition Rule, or link order. Runtime memory errors (segfaults, double free, use-after-free) are non-deterministic and should never be debugged by reading code alone; a sanitizer will find in seconds what code review misses for days.
If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.
- Rebuild with sanitizers before anything else:
-fsanitize=address,undefined -fno-omit-frame-pointer -g. AddressSanitizer reports the exact allocation and free sites for use-after-free and double-free. - For undefined-reference errors, check link order, remembering that with GNU ld libraries must come after the objects that use them, and check for a C/C++ linkage mismatch that needs
extern "C". - Use
nm -C libfoo.a | grep symbolto confirm the symbol is actually present and to see the demangled signature. A signature that differs by aconstis a different symbol. - Enable core dumps (
ulimit -c unlimited) and open them in gdb withgdb ./binary core, thenbt full. A stack trace beats speculation. - For template errors, read the message from the bottom up. The final line is usually the real constraint that failed; everything above is instantiation context.
Tools worth reaching for
-fsanitize=address,undefinedvalgrindgdb / lldbnm -Cldd
Authoritative references
Primary documentation for this error, worth reading before applying any fix in production.
Related C++ errors
- C++: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.32' not foundThe binary was built with a newer GCC than the machine it is running on, and it needs a…
- C++: error: 'format' is not a member of 'std'std::format is C++20 and lives in , which needs both the C++20 flag and a recent enough…
- C++: error: 'uint8_t' does not name a typeThe file uses fixed-width integer types without including , and only ever compiled because…
- C++: error: invalid use of incomplete type 'class Foo'The compiler has seen a forward declaration of Foo but not its definition, and this line…
- C++: error: use of deleted functionThe code tries to call a function that has been explicitly deleted, and nine times out of ten…
- C++: relocation R_X86_64_32S can not be used when making a shared objectA shared library must be loadable at any address, so every object in it needs position…
- C++: runtime error: signed integer overflow (UBSan)Signed integer overflow is undefined behaviour in C and C++. The program may appear to work…
- C++: Segmentation fault (core dumped)Program attempted to access memory it doesn't own (e.g., dereferencing null pointer, buffer…
Browse other categories
- HTTP 494xx client errors, 5xx server errors, redirects, headers and protocol problems.
- JavaScript 42npm resolution, async pitfalls, hydration, memory limits and runtime type…
- Database 41Connections, deadlocks, constraints, replication and memory limits.
- AI 35Rate limits, context windows, GPU memory and model-serving failures.
- Network 35Refused connections, timeouts, resets, MTU problems and port exhaustion.
- Python 35Imports, virtual environments, encoding, concurrency and dependency conflicts.
- Kubernetes 34CrashLoopBackOff, ImagePullBackOff, OOMKilled, RBAC, scheduling and storage.
- Docker 27Daemon connectivity, disk space, image pulls, ports and architecture mismatches.
- System 26Disk space, systemd units, file descriptors, OOM killer and scheduled jobs.
- Cloud 25IAM permissions, quotas, service limits and credential failures.
- Security 25JWT validation, CSRF, OAuth grants, SELinux, SSH host keys and CSP.
- TLS 24Untrusted authorities, expiry, hostname mismatch, chains and cipher negotiation.
Something missing or wrong?
This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.