Summary
In this episode, Jason reveals a common but often overlooked C++ optimization: not defining destructors when they aren't needed. Using Compiler Explorer to demonstrate with both GCC and Clang, he shows how empty or trivial destructors prevent compiler optimizations and disable implicit move operations. Jason demonstrates how the same simple code with unnecessary destructors generates substantially more assembly instructions, especially when containers like std::vector are involved. He emphasizes following the Rule of Zero to allow the compiler to generate optimal code for object lifetime management.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[basic.stc.dynamic.general]51% match -
[c.malloc]48% match -
[class.free]48% match -
[unique.ptr]40% match