[SERVER-42812] Remove superfluous `virtual` keywords from known `overload` appropriate situations. Created: 13/Aug/19  Updated: 29/Aug/23

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: ADAM Martin (Inactive) Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Service Arch
Participants:

 Description   

Each of the forms of:

virtual void f() override final;
virtual void f() override;
virtual void f() final;
virtual void f();
 
void f() override final;
void f() override;
void f() final;
void f();

means something subtly and slightly different.

Each means:

virtual void f() override final;  // is virtual, must override, cannot be overriden
virtual void f() override; // is virtual, must override, may be overriden
virtual void f() final; // is virtual, may be overriden
virtual void f(); // is virtual
 
void f() override final; // require virtual, must override, cannot be overriden
void f() override; // require virtual, must override
void f() final; // require virtual, cannot be overriden
void f(); // may or may not be virtual.

Some things to note:

  • The `virtual override final` form is the same as the `override final` form which is the same as the `final` form.
  • The `virtual override` form is the same as the `override` form.
  • The `virtual final` form may be a 1st generation function!
  • The `virtual` form may ALSO be a 1st generation function!

Looking at all of the forms again:

virtual void f() override final;  // Superfluous syntax for `void f() final;`
virtual void f() override; // Superfluous syntax for `void f() override;`
virtual void f() final; // Dangerous form – may not be overriding
virtual void f(); // Not necessarily the 1st generation function, uncertain.
 
void f() override final; // Superfluous syntax for `void f() final;`
void f() override; // Tersest syntax for this form.
void f() final; // Tersest syntax for this form.
void f(); // Uncertain form.

This means that no more than 1 of the keywords `virtual`, `override`, or `final` should be used on a function declaration. 



 Comments   
Comment by Alex Neben [ 29/Aug/23 ]

I think this is done with this clang-tidy check https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-override.html. Sending this to service arch to decide on priority.

Generated at Thu Feb 08 05:01:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.