AutosarC++17_03-A10.3.3ΒΆ
Virtual functions shall not be introduced in a final class
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Declaring a class as final explicitly specifies that the class cannot be inherited.
Declaring a virtual function inside a class specifies that the function can be overriden in the inherited class, which is inconsistent.
Example
// $Id: A10-3-3.cpp 271927 2017-03-24 12:01:35Z piotr.tanski $
class A {
public:
virtual ~A() = default;
virtual void f() noexcept = 0;
virtual void g() noexcept {}
};
class B final : public A {
public:
void f() noexcept final // Compliant
{}
void g() noexcept override // Non-compliant
{}
virtual void h() noexcept = 0; // Non-compliant
virtual void z() noexcept // Non-compliant
{}
};
See Also
- HIC++ v4.0 [8]: 9.1.5 Do not introduce virtual functions in a final class.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
virtual_method |
Virtual functions shall not be introduced in a final class. |
None |
False |
virtual_method_override |
Virtual functions shall not be overridden without final in a final class. |
None |
False |
Options
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.