From 17b8e80d1602b0d494b6691c2801fd1f81c60094 Mon Sep 17 00:00:00 2001 From: leekillough <15950023+leekillough@users.noreply.github.com> Date: Sun, 10 Nov 2024 12:34:21 -0600 Subject: [PATCH] Fix mistake about `final` and `override` not affecting `final` classes; reword enforcement to be clearer --- CppCoreGuidelines.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index e93e8f8fd..9511a2a67 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -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. 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. +* Flag function overrides in derived classes containing neither `override` nor `final`. * Flag function declarations that use more than one of `virtual`, `override`, and `final`. ### C.129: When designing a class hierarchy, distinguish between implementation inheritance and interface inheritance