Apply Rule of Zero across remaining utility/ empty destructors#694
Open
lyskov-ai wants to merge 1 commit into
Open
Apply Rule of Zero across remaining utility/ empty destructors#694lyskov-ai wants to merge 1 commit into
lyskov-ai wants to merge 1 commit into
Conversation
Remove user-declared destructors and out-of-line `= default` definitions
where the implicit (or `= default`) destructor is correct, and clarify a
non-trivial destructor by deleting copy/move on its owner.
* Remove empty `~Foo() {}` / `~Foo() override {}` where the implicit
destructor is already correct (and virtual via base when needed):
- utility/Bound.hh, utility/excn/Exceptions.hh,
utility/io/ocstream.hh, utility/keys/AutoKey.hh,
utility/keys/UserKey.hh.
* Convert `~Foo() {}` to `~Foo() = default;` for polymorphic root
classes whose implicit destructor would otherwise be non-virtual:
- utility/Show.hh, utility/factory/WidgetFactory.hh,
utility/io/irstream.hh, utility/io/orstream.hh,
utility/keys/Key.hh, utility/options/Option.hh.
* Drop `= default` destructor pairs (.hh declaration + .cc definition)
for classes inheriting from utility::VirtualBase, which already
supplies a virtual destructor:
- utility/heap, utility/integer_mapping (subset_mapping),
utility/recent_history_queue, utility/io/GeneralFileManager
(GeneralFileContents{,Vector}), utility/tag/Tag.
* utility/io/mpistream.hh: explicitly `= delete` the copy ctor and
copy assignment of `basic_mpi_streambuf` because its destructor
calls `flush_final()` (closes the MPI channel); replace the empty
`~basic_mpi_ostream() override {}` with `= default`.
lyskov
approved these changes
May 12, 2026
roccomoretti
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bundle of small Rule-of-Zero / clarity fixes across
utility/for classesnot covered by any other open PR. All changes are observably no-ops at
runtime (each destructor body either was empty or
= default); the goalis to remove redundant declarations and document a deliberate non-trivial
case.
~Foo() {}where the implicit destructor is alreadycorrect (virtual is preserved via the base class when relevant):
Bound,Exception,ocstream,AutoKey,UserKey.~Foo() {}to~Foo() = default;for polymorphic rootclasses (no virtual base destructor to inherit), so the destructor
stays virtual:
Show,WidgetFactory,irstream,orstream,Key,Option.= defaultdestructor pairs (.hh decl + .cc def) forclasses that inherit from
utility::VirtualBase, which alreadysupplies a
virtual ~VirtualBase() = default;:heap,subset_mapping,recent_history_queue,GeneralFileContents,GeneralFileContentsVector,Tag.utility/io/mpistream.hh: the destructor ofbasic_mpi_streambufis not trivial — it calls
flush_final(), which sends the closemessage on the MPI channel. Add explicit
= deletefor its copyconstructor and copy-assignment so an accidental copy can't trigger
the side effect twice. Also replace the empty
~basic_mpi_ostream() override {}with= default.The diff is intentionally smaller than the usual 128-line bundle target:
most other empty-destructor candidates in
utility/are already coveredby my open sibling PRs (#690 BitSet/BitVector, #691 keys containers, #692
utility/ helpers, #693 utility/options empty dtors). This PR sweeps the
classes those don't touch.
Verified by a clean
mode=debugbuild (python3 ./scons.py -j16 mode=debug,zero errors, no new warnings).