-
Notifications
You must be signed in to change notification settings - Fork 273
Get legalistic about use of virtual with override #2055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get legalistic about use of virtual with override #2055
Conversation
From my point of view you might as well flip a coin, but I'm a strong proponent of consistency: always use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to nail my colours to the mast...
...but I'm not brave enough to merge it, so someone else can do that :-) |
My preference would be to not add the redundant virtual. Both the default cpplint and clang-tidy's My argument against the consistency argument would be that if you're only going to check the prefix of the function for the behaviour you could also read an override as introducing a new virtual function instead. Also, you should always check the postfix anyway for EDIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a little clearer. Though an en-masse cleanup should also be submitted in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, neither virtual
nor override
are required. Using virtual
to visually mark overridden functions is a relict from pre-C++11 times.
I agree with @hannes-steffenhagen-diffblue that the fact that clang-tidy offers an option to clean up joint use of virtual
and override
is a strong argument for getting rid of the remaining redundancies in our code bases.
So, are we doing override without virtual? |
I think we have three votes for including virtual and two against. Is @kroening against? Then we can have an exact tie and do nothing. |
Hm, the Google C++ coding style (which we frequently follow) says use override but no virtual. |
@NathanJPhillips If you're intent on starting a war over this I can offer to supply one (or both) sides with ammunition at very reasonable prices... I think I'm with the "does it really matter" faction, or possibly the "add it to the linter and let it change naturally" group, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll go for 'no virtual', and it will be a linter recommendation.
#2253 clarifies the rule in the coding standard and enables the corresponding check in cpplint. |
I recently had a comment on a PR complaining that I used the redundant
virtual
on a method declaration that I markedoverride
.I replied that the redundant virtual is useful documentation as it allows developers to see whether a function is virtual in a single place without having to check the beginning and the end of the declaration.
Another reviewer pointed out that our linter was specifically adjusted to allow this format here: a7c24fb#diff-4abdbb2a75f622bb69ca7ae19beee7c6R5647.
An analysis of the code base for CBMC shows that we have 457 uses of
override
, of which 154 combine it withvirtual
. Deeptest has a similar proportion with 22 of 64 uses using the combined version.My hope with this PR is that it will ignite a style war that will get nowhere and result in this PR being closed. This will then be the definitive point of reference for allowing people to do whatever they feel most comfortable with.