You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add a cross-reference to C.139 and note that it doesn't matter whether
a function is declared with override or final if the whole class is
already final.
- Fix C.139 to make it clearer that it's about `final` on classes.
Copy file name to clipboardExpand all lines: CppCoreGuidelines.md
+8-4Lines changed: 8 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -6821,7 +6821,7 @@ Designing rules for classes in a hierarchy summary:
6821
6821
* [C.136: Use multiple inheritance to represent the union of implementation attributes](#Rh-mi-implementation)
6822
6822
* [C.137: Use `virtual` bases to avoid overly general base classes](#Rh-vbase)
6823
6823
* [C.138: Create an overload set for a derived class and its bases with `using`](#Rh-using)
6824
-
* [C.139: Use `final` sparingly](#Rh-final)
6824
+
* [C.139: Use `final` on classes sparingly](#Rh-final)
6825
6825
* [C.140: Do not provide different default arguments for a virtual function and an overrider](#Rh-virtual-default-arg)
6826
6826
6827
6827
Accessing objects in a hierarchy rule summary:
@@ -7080,6 +7080,10 @@ We want to eliminate two particular classes of errors:
7080
7080
* **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)
7081
7081
* **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 may have intended to create either a new virtual function or a new non-virtual function)
7082
7082
7083
+
Note: On a class defined as `final`, it doesn't matter whether you put `override` or `final` on an individual virtual function.
7084
+
7085
+
Note: Use `final` on functions sparingly. It does not necessarily lead to optimization, and it precludes further overriding.
7086
+
7083
7087
##### Enforcement
7084
7088
7085
7089
* Compare virtual function names in base and derived classes and flag uses of the same name that does not override.
@@ -7650,11 +7654,11 @@ For variadic bases, C++17 introduced a variadic form of the using-declaration,
7650
7654
7651
7655
Diagnose name hiding
7652
7656
7653
-
### <a name="Rh-final"></a>C.139: Use `final` sparingly
7657
+
### <a name="Rh-final"></a>C.139: Use `final` on classes sparingly
7654
7658
7655
7659
##### Reason
7656
7660
7657
-
Capping a hierarchy with `final` is rarely needed for logical reasons and can be damaging to the extensibility of a hierarchy.
7661
+
Capping a hierarchy with `final` classes is rarely needed for logical reasons and can be damaging to the extensibility of a hierarchy.
7658
7662
7659
7663
##### Example, bad
7660
7664
@@ -7688,7 +7692,7 @@ However, misuses are (or at least have been) far more common.
7688
7692
7689
7693
##### Enforcement
7690
7694
7691
-
Flag uses of `final`.
7695
+
Flag uses of `final` on classes.
7692
7696
7693
7697
7694
7698
### <a name="Rh-virtual-default-arg"></a>C.140: Do not provide different default arguments for a virtual function and an overrider
0 commit comments