AutosarC++17_10-A10.3.2

Each overriding virtual function shall be declared with the override or final specifier

Required inputs: IR

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 [8]: 10.2.1 Use the override special identifier when overriding a virtual function
  • C++ Core Guidelines [10]: 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

allow_final

allow_final : bool = True

If set to True, don't report overriding virtual functions declared with final.
 

ignore_destructors

ignore_destructors : bool = False

If set to False, also report destructors. Note that not all compilers support this.