From a446e940a8212dd61774857392129e26895342af Mon Sep 17 00:00:00 2001 From: Sergey Zubkov Date: Thu, 8 May 2025 15:10:53 -0400 Subject: [PATCH] [C.128] reword the note on final classes the issue was raised that it can be interpreted as a claim that final and override are the same; this attempts to make it harder to misread closes #2235 --- CppCoreGuidelines.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 7e006d2..db3291c 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -7432,13 +7432,13 @@ 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`, each individual virtual function should use either `override` or `final`; there is no semantic difference in this case. 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. +* Compare virtual function names in base and derived classes and flag uses of the same name that do not override. * Flag overrides with neither `override` nor `final`. * Flag function declarations that use more than one of `virtual`, `override`, and `final`.