The C++ core guidelines contain the following advice regarding the virtual
, override
and final
specifiers, specifically relating to derived class destructors:
If a base class destructor is declared virtual, one should avoid declaring derived class destructors virtual or override. Some code base and tools might insist on override for destructors, but that is not the recommendation of these guidelines.
Sure enough, clang-tidy
is one of those tools that goes against the recommendation.
If I do not specify either virtual
or override
, running clang-tidy
emits the following warning:
warning: annotate this function with 'override' or (rarely) 'final' [modernize-use-override]
or, if specified just as virtual
:
warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [modernize-use-override]
My question
Given that specifying override
, in particular, has the advantage of (at least) ensuing you have correctly specified the base class destructor as virtual
, my question boils down to the following specific parts:
- What, if any, are the arguments in favour of not specifying
virtual
oroverride
on derived class destructors? - In your opinion, should I lean more towards the
clang-tidy
advice, or towards the C++ core guidelines advice?