[webkit-dev] virtual destructor annotations in subclasses

Yury Semikhatsky yurys at chromium.org
Tue Oct 8 16:24:28 PDT 2019

Hi all,

This question came up in a code review where I annotated subclass's
destructor with 'override':

class SuperClass {
  virtual ~SuperClass() {}

class Subclass : public SuperClass {
  ~Subclass() *override*;

The style guide recommends
annotating overriden methods with either 'override' or 'final'. At the same
time with a very few exceptions, the vast majority of the subclasses in
WebKit annotate their destructors with 'virtual' keyword. It might be
because some of the code predates c++11 and virtual was the default
choice back then. In any case it prevents the compiler from generating
errors when super destructor is accidentally not made virtual.

So my question is if there is a reason to exempt destructors from the above
rule and mark them virtual in subclasses or they should be annotated with
override/final similar to other virtual methods?

In the latter case we could update existing code once  by automatically
generating fix with clang-tidy.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20191008/7901a1d9/attachment.html>

More information about the webkit-dev mailing list