-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Fix mistake about final
and override
not affecting final
classes; reword enforcement to be clearer
#2235
base: master
Are you sure you want to change the base?
Conversation
…s; reword enforcement to be clearer
Editors call: Thanks! The text already says what you want, but we see it could be clearer. The point of C.128 is that on such a virtual function, the programmer should write one of |
@@ -7428,14 +7428,14 @@ We want to eliminate two particular classes of errors: | |||
* **implicit virtual**: the programmer intended the function to be implicitly virtual and it is (but readers of the code can't tell); or the programmer intended the function to be implicitly virtual but it isn't (e.g., because of a subtle parameter list mismatch); or the programmer did not intend the function to be virtual but it is (because it happens to have the same signature as a virtual in the base class) | |||
* **implicit override**: the programmer intended the function to be implicitly an overrider and it is (but readers of the code can't tell); or the programmer intended the function to be implicitly an overrider but it isn't (e.g., because of a subtle parameter list mismatch); or the programmer did not intend the function to be an overrider but it is (because it happens to have the same signature as a virtual in the base class -- note this problem arises whether or not the function is explicitly declared virtual, because the programmer might have intended to create either a new virtual function or a new non-virtual function) | |||
|
|||
Note: On a class defined as `final`, it doesn't matter whether you put `override` or `final` on an individual virtual function. | |||
Note: On a class defined as `final`, individual virtual functions cannot be overridden whether or not you put `final` on them. However, using `override`, or `final` without `virtual`, on a member function of a class marked `final` ensures that it overrides a base class virtual function. |
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.
Your first sentence is confusing. It reads like you're saying that virtual functions can't be overridden in the final class. But I think what you mean is that they can't be overridden again by something derived from the final class, because nothing can derive from it. It's just a confusing way to say "you can't derive from a final class"!
The second sentence is long and awkward.
* Compare virtual function names in base and derived classes and flag uses of the same name that does not override. | ||
* Flag overrides with neither `override` nor `final`. | ||
* Compare virtual function names in base and derived classes and flag uses of the same name that do not have the same signatures and thus do not override. | ||
* Flag function overrides in derived classes containing neither `override` nor `final`. |
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.
This change isn't an improvement. Overrides have to be in derived classes, so adding that is redundant.
|
||
Note: Use `final` on functions sparingly. It does not necessarily lead to optimization, and it precludes further overriding. | ||
|
||
##### Enforcement | ||
|
||
* Compare virtual function names in base and derived classes and flag uses of the same name that does not override. | ||
* Flag overrides with neither `override` nor `final`. | ||
* Compare virtual function names in base and derived classes and flag uses of the same name that do not have the same signatures and thus do not override. |
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.
Apart from correcting "does" to "do" (which should be fixed) this added text seems redundant, but maybe it helps clarify it if somebody isn't sure about the definition of override.
Fix mistake about
final
andoverride
not affectingfinal
classes; reword enforcement to be clearer.override
andfinal
onfinal
classesfinal
, it doesn't matter whether you putoverride
orfinal
on an individual virtual function.That is incorrect. The semantics change if
override
orfinal
is used on an individual virtual function. Correction:final
, individual virtual functions cannot be overridden whether or not you putfinal
on them. However, usingoverride
, orfinal
withoutvirtual
, on a member function of a class markedfinal
ensures that it overrides a base class virtual function.Better Wording
override
norfinal
.Better wording:
override
norfinal
.