Where:We already use it extensively throughout Chrome and Blink. It'd be easy to update this.
In addition, I believe we should encourage that developers only use one of virtual|override|final (this is what the Google C++ style guide mandates). There's never a reason to use more than one: override implies virtual, and final implies virtual and override.
Daniel
On Tue, Sep 23, 2014 at 2:25 PM, Daniel Cheng <dch...@chromium.org> wrote:Where:We already use it extensively throughout Chrome and Blink. It'd be easy to update this.This seems fine. What advice would we give for new code? Use the lowercase versions always, be consistent with the file, convert as you go?
Big +1 to nuking OVERRIDE and FINAL in favor of "override" and "final" now that it's formally supported everywhere, and to updating our plugin if necessary.
--
Incidentally, if we're going to use a tool to convert all OVERRIDE to override, I suggest the tool also remove the "virtual" keyword in such cases in the same pass, so we're consistent from the beginning and don't have to do two cleanup passes.
PK
Will we follow the Google style guide which prohibits virtual when override is present? For example:void Foo() override;notvirtual void Foo() override;
In addition, I believe we should encourage that developers only use one of virtual|override|final (this is what the Google C++ style guide mandates). There's never a reason to use more than one: override implies virtual, and final implies virtual and override.
Last time we tried this override and final produced different warnings so you really did need both. Has that changed? For example if you remove the super class method entirely does it fail to compile if you only have final and not virtual and override?
In blink final is an assertion from the author that they're the leaf for that method or class. If you need to extend something you're welcome to remove it and mark your new method final (or more likely your whole class). Having it is important for performance (and not harmful like inline) and also security. We should not change the encouragement of marking all leaves in blink final.
--
* Blink uses final in a different way than the rest of chromium. That's fine.
Blink marks lots of methods final (see https://code.google.com/p/chromium/issues/detail?id=333316). My understanding from the "when to use final" thread was that we don't want to do this in chromium (?)
> --
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev
+2
If the security wins are meaningful, to me that overrides any of the design concerns.
And I say that as a person who seriously cares about design.
I just hope we provide guidance on when/how the security gains are meaningful, for all codebases.
I started to draft a patch, but two questions:1) Do we want to address style at all, or just assume that people will delegate to the Google C++ style guide?2) We've never annotated our destructors with override or final, but the Google C++ style guide seems to indicate this is preferred. Is this the approach we want to take as well?
I started to draft a patch, but two questions:1) Do we want to address style at all, or just assume that people will delegate to the Google C++ style guide?
On Wed, Sep 24, 2014 at 2:33 PM, Daniel Cheng <dch...@chromium.org> wrote:I started to draft a patch, but two questions:1) Do we want to address style at all, or just assume that people will delegate to the Google C++ style guide?2) We've never annotated our destructors with override or final, but the Google C++ style guide seems to indicate this is preferred. Is this the approach we want to take as well?I'd just say "Using override instead of OVERRIDE is recommended for new code" for now, and then add more things later, once the plugin actually supports them.
Since this has surprised some people, I wanted to make sure there aren't broader objections from Chromium developers before completing this migration.Explicitly annotate overrides of virtual functions or virtual destructors with an override or (less frequently) final specifier.Today, Chromium only uses 'virtual' for destructors. Does anyone have objections to just using the Google C++ style rule here?
~Derived() and ~Base() is just a C++ syntax to denote a class's destructor and if the base class has virtual destructor, the derived class's destructor is overriding it. I think it is totally expected/advised to use "override" on destructors as well for the same compiler assistance/checking as with regular virtual methods.
/daniel
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
Wouldn't that case be better covered by a rule like: if Base has a non-override virtual method (so we expect there to be cases where Base* is secretly a Derived*), it should either have a virtual destructor or a protected one? Seems you could otherwise just as easily forget to add the virtual on Derived.
Or the simpler: if there's any virtual method, the destructor must also be virtual, since you're paying for the vtable already anyway. I could have sworn we already had that rule, but maybe I'm hallucinating.
On Mon, Oct 20, 2014 at 3:00 PM, David Benjamin <davi...@chromium.org> wrote:Wouldn't that case be better covered by a rule like: if Base has a non-override virtual method (so we expect there to be cases where Base* is secretly a Derived*), it should either have a virtual destructor or a protected one? Seems you could otherwise just as easily forget to add the virtual on Derived.Or the simpler: if there's any virtual method, the destructor must also be virtual, since you're paying for the vtable already anyway. I could have sworn we already had that rule, but maybe I'm hallucinating.The style guide actually says that classes with virtual methods should have virtual destructors, so in some sense we do have that kind of rule.
On Mon, Oct 20, 2014 at 3:00 PM, David Benjamin <davi...@chromium.org> wrote:Wouldn't that case be better covered by a rule like: if Base has a non-override virtual method (so we expect there to be cases where Base* is secretly a Derived*), it should either have a virtual destructor or a protected one? Seems you could otherwise just as easily forget to add the virtual on Derived.Or the simpler: if there's any virtual method, the destructor must also be virtual, since you're paying for the vtable already anyway. I could have sworn we already had that rule, but maybe I'm hallucinating.The style guide actually says that classes with virtual methods should have virtual destructors, so in some sense we do have that kind of rule.It doesn't seem to be enforced by a compiler flag: https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/chromeos/file_system_provider/observer.h&l=18Is there a warning we can/should enable for this?
You have a virtual ~Base(); and virtual ~Derived(). Someone goes in and removes "virtual" from ~Base() without giving it a second though. ~Derived() is still marked as virtual, so the code compiles and everything "works" but run-time functionality is broken. If ~Derived() is marked "override" instead, removing "virtual" from ~Base() instantly breaks the build.