Skip to content

Commit 945b34d

Browse files
committed
Closes #1574
- 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.
1 parent 63e2cd0 commit 945b34d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

CppCoreGuidelines.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6821,7 +6821,7 @@ Designing rules for classes in a hierarchy summary:
68216821
* [C.136: Use multiple inheritance to represent the union of implementation attributes](#Rh-mi-implementation)
68226822
* [C.137: Use `virtual` bases to avoid overly general base classes](#Rh-vbase)
68236823
* [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)
68256825
* [C.140: Do not provide different default arguments for a virtual function and an overrider](#Rh-virtual-default-arg)
68266826

68276827
Accessing objects in a hierarchy rule summary:
@@ -7080,6 +7080,10 @@ We want to eliminate two particular classes of errors:
70807080
* **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)
70817081
* **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)
70827082

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+
70837087
##### Enforcement
70847088

70857089
* 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,
76507654

76517655
Diagnose name hiding
76527656

7653-
### <a name="Rh-final"></a>C.139: Use `final` sparingly
7657+
### <a name="Rh-final"></a>C.139: Use `final` on classes sparingly
76547658

76557659
##### Reason
76567660

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.
76587662

76597663
##### Example, bad
76607664

@@ -7688,7 +7692,7 @@ However, misuses are (or at least have been) far more common.
76887692

76897693
##### Enforcement
76907694

7691-
Flag uses of `final`.
7695+
Flag uses of `final` on classes.
76927696

76937697

76947698
### <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

Comments
 (0)