STL: Should we avoid repeating `virtual` for `override` functions?

Created on 15 Nov 2019  路  5Comments  路  Source: microsoft/STL

Currently, we follow a convention of saying both virtual and override on derived implementations. One of many examples:

https://github.com/microsoft/STL/blob/58bb49d63d92e7a0346a05af29816aeea6b4cf0f/stl/inc/functional#L861-L863

We started doing this when override was new and we weren't familiar with reading it. Now that we are, should we avoid this redundancy? The advantage to doing so, aside from reducing verbosity, is that it would make the remaining virtual occurrences stand out. Those indicate either base declarations, or derived implementations that should be marked override (see #207 for that).

decision needed enhancement

Most helpful comment

this is what C.128 says to do. go for it.

All 5 comments

this is what C.128 says to do. go for it.

Has there ever been a proposal to allow override before the declaration of a function? Imho, having a visual clue consistently at the front is the only advantage of using both virtual and override.

According to my understanding, that would conflict with override's status as a context-sensitive keyword. In C++11 through C++20, you can have struct override, and that can appear as a return type of a function: override meow(int).

Urgs. Makes sense :(.
Thanks

I think that it makes sense to decide towards removal of superfluous virtual and address #207 with clang-tidy.

See https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-override.html

I'm not sure however how to integrate this into build.

Was this page helpful?
0 / 5 - 0 ratings