On 2017-05-12 9:55 AM, Ehsan Akhgari wrote:
This reminded me of
https://bugzilla.mozilla.org/show_bug.cgi?id=1332680 (and
https://bugzilla.mozilla.org/show_bug.cgi?id=1332682 )

Adding -Wsuggest-final-types and -Wsuggest-final-methods and looking
at the output seems pretty low-effort to find a lot of more
opportunities for this. (Unless I'm misunderstanding things).

Plus, it benefits security!
Yes, this is indeed a good point.  Even though this will really only
have a measurable impact on performance if the functions are called in
hot code, it seems like a shame to not listen to the compiler when it
tells you I could make your code faster if you added this keyword in a
bunch of places.  :-)

Should the Mozilla Coding Style document recommend that all new classes use `final` unless they are designed to be derived? It would be a good habit even for simple classes that don't derive from a base class.

Also, Herb Sutter recommends [1] that all base classes should either have a public virtual destructor or protected non-virtual destructor. This prevents the problem where a derived class's non-virtual destructor doesn't get called if the object is deleted through a pointer to a base class.

So all classes would either:

- be a final class,
- have a public virtual destructor, or
- have a protected non-virtual dtor (possibly an empty inline dtor)


[1] http://www.gotw.ca/publications/mill18.htm
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to