tldr; Should we update the style guide to explicitly tell you to mark a class final not just a destructor?
In the style guide we encourage people to annotate a destructor as final. This is effectively the same as marking the class final but less obvious and you get a worse error.
"Explicitly annotate overrides of virtual functions or virtual destructors with exactly one of an override
or (less frequently) final
specifier. Do not use virtual
when declaring an override. Rationale: A function or destructor marked override
or final
that is not an override of a base class virtual function will not compile, and this helps catch common errors. The specifiers serve as documentation; if no specifier is present, the reader has to check all ancestors of the class in question to determine if the function or destructor is virtual or not."
Here's
one example in the code base where we annotate the destructor final.
In newer versions of clang there is a warning -Wfinal-dtor-non-final-class which issues a warning (currently disabled in chrome) to add final to the class. eg.
external/base/task/sequence_manager/sequence_manager_impl.cc:156:27: warning: class with destructor marked 'final' cannot be inherited from [-Wfinal-dtor-non-final-class]
~NativeWorkHandleImpl() final {
^
external/base/task/sequence_manager/sequence_manager_impl.cc:145:28: note: mark 'base::sequence_manager::internal::SequenceManagerImpl::NativeWorkHandleImpl' as 'final' to silence this warning
class SequenceManagerImpl::NativeWorkHandleImpl : public NativeWorkHandle {
Changes that implemented this...
Should the style guide be updated to reflect this, and is it a prerequisite to cleaning up the instances in the code per this
bug? And should the guidance be to annotate both, or only the class?