Qt-Autosar-A10.3.2¶
Each overriding virtual function shall be declared with the override or final specifier
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Explicit use of the override or final specifier enables the compiler to catch mismatch of types and names between base and derived classes virtual functions.
Note that this rule applies to virtual destructor overriders, too.
Also, note that this rule applies to a pure virtual function which overrides another pure virtual function.
Example
// $Id: A10-3-2.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
class A
{
public:
virtual ~A() {}
virtual void F() noexcept = 0;
virtual void G() noexcept {}
virtual void Z() noexcept {}
virtual A& operator+=(A const& oth) = 0;
};
class B : public A
{
public:
~B() override {} // Compliant
void F() noexcept // Non-compliant
{
}
virtual void G() noexcept // Non-compliant
{
}
void Z() noexcept override // Compliant
{
}
B& operator+=(A const& oth) override // Compliant
{
return *this;
}
};
class C : public A
{
public:
~C() {} // Non-compliant
void F() noexcept override // Compliant
{
}
void G() noexcept override // Compliant
{
}
void Z() noexcept override // Compliant
{
}
C& operator+=(A const& oth) // Non-compliant
{
return *this;
}
};
See Also
- HIC++ v4.0 [9]: 10.2.1 Use the override special identifier when overriding a virtual function
- C++ Core Guidelines [11]: C.128: Virtual functions should specify exactly one of virtual, override, or final.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
missing_override |
Override of functions is only permitted with keyword override/final. |
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
allow_final¶
allow_final : bool = True
ignore_destructors¶
ignore_destructors : bool = False