AutosarC++18_10-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 overridden in the inherited class, which is inconsistent.
Example
// $Id: A10-3-3.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
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 [9]: 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.