I mail you about this because I just did this for users of a random
Chrome class and found two separate instances where a refactoring
change caused some code to silently stop being called. It is trivial
to add these annotations and they are verified on all
platforms/compilers: Windows, Mac, and Linux.
---
Here is how OVERRIDE works:
class MyInterface {
virtual void FooBar();
};
class MyImplementation : public MyInterface {
MyImplementation();
// Implementation of MyInterface
virtual void FooBar() OVERRIDE;
};
This keyword makes it a compile failure if MyImplementation's FooBar()
is no longer actually overriding a virtual method in a parent class.
That can happen if someone changes the signature of the parent, or
whether MyImplementation actually implements MyInterface, or anything
else like that.
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
I'm not sure how trivial that lint rule is, but if you could write it
you could try it out.
I fear it might be kinda annoying to need to tag every function in
this manner, but I'd have to see it.
> Small side note: using this requires adding #include
> "base/compiler_specific.h" to the header file. Presumably that's fine.
> (internal thought train: to me "compiler specific" sounds like a good header
> to include if I'm writing compiler specific features, not when using a
> cross-platform compiler independent abstraction. c.f. the definition of
> int64 is compiler specific, but I don't advertise this fact in my include
> list)
If it makes you feel better, the file has many other macros of this form.
--
(Side note:
There are two classes of problems where OVERRIDE helps:
1.) You rename a base class method you fail to do the renaming
in all subclasses
2.) You change the parameter list of a base class method and you
fail to update the overrides
2 is caught by -Woverloaded-virtual on the clang bots even without OVERRIDE.)
Is OVERRIDE still encouraged in a derived class when the base class defines the method as a pure virtual?On the no side: the compiler will already catch that problem when clients instantiate the derived class.On the yes side: simple to state "Always use OVERRIDE". Also future-proofs for the likely-rare case of the base class getting an implementation, and the implementation later changing the signature.
On Tue, Nov 8, 2011 at 11:43 AM, Chris Bentzel <cben...@chromium.org> wrote:Is OVERRIDE still encouraged in a derived class when the base class defines the method as a pure virtual?On the no side: the compiler will already catch that problem when clients instantiate the derived class.On the yes side: simple to state "Always use OVERRIDE". Also future-proofs for the likely-rare case of the base class getting an implementation, and the implementation later changing the signature.+1
Is OVERRIDE still encouraged in a derived class when the base class defines the method as a pure virtual?On the no side: the compiler will already catch that problem when clients instantiate the derived class.On the yes side: simple to state "Always use OVERRIDE". Also future-proofs for the likely-rare case of the base class getting an implementation, and the implementation later changing the signature.