practicalswift
commented at 3:07 PM on June 19, 2017:
contributor
Use the override specifier (C++11) where we expect to be overriding the virtual function of a base class.
Rationale: By using the override specifier (C++11) we're guaranteed a compile-time error if our stated override expectation is not fulfilled. This avoids gotchas with regards to function renames, function signature changes, etc. Additionally it clarifies the intended behaviour for the reader.
practicalswift force-pushed on Jun 19, 2017
practicalswift force-pushed on Jun 19, 2017
fanquake added the label Refactoring on Jun 20, 2017
TheBlueMatt
commented at 4:37 PM on June 20, 2017:
member
Nice! Is there an automated way I can check that you didn't miss any, or did you do it by hand?
theuni
commented at 6:16 PM on June 20, 2017:
member
-Wsuggest-override should do it, though google says it may be inconsistent wrt 'final'.
theuni
commented at 6:50 PM on June 20, 2017:
member
There are a bunch more in qt, even ignoring protobufs.
Concept ACK, but without being able to enforce, I fear that this might turn into another -Wshadow that drove @laanwj crazy.
practicalswift
commented at 7:09 PM on June 20, 2017:
contributor
@theuni Can you give some context for the -Wshadow incident?
MarcoFalke
commented at 7:23 PM on June 20, 2017:
member
@practicalswift Different compilers and different versions of the same compiler have non-matching notions of what "shadow" means. Some of them even had false positives. Effectively it was impossible to enforce this rule when the code was written by a developer and we had weekly cleanup pulls to "fix wshadow warnings". Let's avoid that this turns into a avalanche of "add override specifier" pulls.
practicalswift
commented at 7:25 PM on June 20, 2017:
contributor
@MarcoFalke Agreed! Just out of curiosity, has anyone tried to add proper override specifiers (project wide) before?
practicalswift force-pushed on Jun 20, 2017
practicalswift force-pushed on Jun 20, 2017
practicalswift
commented at 8:30 PM on June 20, 2017:
contributor
@TheBlueMatt I believe the current version is 100 % complete with the exception of the src/qt/ and src/univalue/ directories which I omitted intentionally. Please let me know if you find any counterexamples – cases which are not marked override in this PR but for which override should be used.
TheBlueMatt
commented at 12:57 AM on June 21, 2017:
member
utACKd39888d178fd72235c2aeedb97d3b7f99260da38
sipa
commented at 1:03 AM on June 21, 2017:
member
As adding override can never cause a behaviour change, utACK-because-it-compiles d39888d178fd72235c2aeedb97d3b7f99260da38
laanwj
commented at 4:38 PM on June 21, 2017:
member
@theuni Can you give some context for the -Wshadow incident?
It got increasingly heated over time, until we finally decided to hack the warning out again.
Concept ACK, but without being able to enforce, I fear that this might turn into another -Wshadow that drove @laanwj crazy.
Do compilers agree on when override should be used?
We have a few uses of override in the code since #10550 and I don't think it has given any issues.
I thnk I've only seen warnings from when override was applied to part of the methods instead of the entire class. Clang does this.
I don't think this can be as bad as Wshadow, where different versions of compilers had different interpretations. Also new classes aren't introduced that frequently.
So I think it's ok...
theuni
commented at 7:02 PM on June 21, 2017:
member
@laanwj I'm not worried about adding overrides, I definitely think we should!
I was only suggesting that because we can't enforce them with static analysis, we'll occasionally forget them and end up with one-off PRs like this one. Which is fine by me :)
clang/gcc both have warnings that can be enabled, but sadly we can't use them by default because:
Apparently gcc still warns about missing override when 'final' is used instead
Our dependencies don't necessarily use them, so we're flooded with warnings for qt/protobufs/leveldb.
laanwj
commented at 2:15 PM on June 24, 2017:
member
Apparently gcc still warns about missing override when 'final' is used instead
From what I understand, override marks a method as being overridden. final marks it as non-overridable. As they work in the opposite direction through the inheritance hierarchy I don't see why one would be a replacement for the other?
Our dependencies don't necessarily use them, so we're flooded with warnings for qt/protobufs/leveldb.
That's a good point. Let's indeed not enable those warnings by default, just try to use it in our own code where we can (as this PR does).
gmaxwell
commented at 8:26 PM on June 27, 2017:
contributor
@sipa I thought the value of adding override is catching some bugs that would arise through renames. As a result blinding adding it wouldn't be a great idea, even though it can never cause a change in behavior because doing so would undermine the advantage of it, no?
theuni
commented at 9:08 PM on June 27, 2017:
member
@gmaxwell I believe @sipa meant the fact that it compiles is good enough because 'override' triggers an error if it doesn't actually override anything. If the function signature ever changes (on accident), it will no longer override its base, and will fail to compile.
I looked these up to make sure that they're actual errors rather than being left up to compilers to decide:
§10.3.5
If a virtual function is marked with the virt-specifier override and does not override a member function of a base class, the program is ill-formed.
§9.2.9:
A virt-specifier-seq shall contain at most one of each virt-specifier. A virt-specifier-seq shall appear only in the declaration of a virtual member function.
sipa
commented at 11:00 PM on June 27, 2017:
member
Needs rebase.
Use the override specifier (C++11) where we expect to be overriding the virtual function of a base classaa95947ded
practicalswift force-pushed on Jun 28, 2017
practicalswift
commented at 12:12 AM on June 28, 2017:
contributor
Rebased! :-)
laanwj assigned laanwj on Jun 28, 2017
laanwj merged this on Jun 28, 2017
laanwj closed this on Jun 28, 2017
laanwj referenced this in commit 9a941a1010 on Jun 28, 2017
PastaPastaPasta referenced this in commit 357cb3af95 on Jul 6, 2019
PastaPastaPasta referenced this in commit 61cbfef59e on Jul 6, 2019
PastaPastaPasta referenced this in commit faf8c63221 on Jul 6, 2019
PastaPastaPasta referenced this in commit 803c3dcacf on Jul 8, 2019
PastaPastaPasta referenced this in commit 28abe148d9 on Jul 9, 2019
PastaPastaPasta referenced this in commit e7f8599bd1 on Jul 11, 2019
PastaPastaPasta referenced this in commit 4926dfab97 on Jul 13, 2019
PastaPastaPasta referenced this in commit 9bcadebf77 on Jul 17, 2019
barrystyle referenced this in commit 1a11fe8843 on Jan 22, 2020
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2026-04-16 15:15 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me