AutosarC++17_03-A10.1.1

Class shall not be derived from more than one base class which is not an interface class

Required inputs: IR

Rationale

Multiple inheritance exposes derived class to multiple implementations. This makes the code more difficult to maintain.

See: Diamond-Problem, Interface-Class

Example
// $Id: A10-1-1.cpp 271715 2017-03-23 10:13:51Z piotr.tanski $
#include <cstdint>
class A {
public:
void f1() noexcept(false) {}

private:
std::int32_t x{0};
std::int32_t y{0};
};
class B {
public:
void f2() noexcept(false) {}

private:
std::int32_t x{0};
};
class C : public A,
  public B // Non-compliant - A and B are both not interface classes
{};
class D {
public:
virtual ~D() = 0;
virtual void f3() noexcept = 0;
virtual void f4() noexcept = 0;
};
class E {
public:
static constexpr std::int32_t value{10};

virtual ~E() = 0;
virtual void f5() noexcept = 0;
};
class F : public A,
  public B,
  public D,
  public E // Non-compliant - A and B are both not interface classes
{};
class G : public A,
  public D,
  public E // Compliant - D and E are interface classes
{};
See Also
  • JSF December 2005 [7]: AV Rule 88 Multiple inheritance shall only be allowed in the following restricted form: n interfaces plus m private implementations, plus at most one protected implementation.
  • HIC++ v4.0 [8]: 10.3.1 Ensure that a derived class has at most one base class which is not an interface class.
  • C++ Core Guidelines [10]: C.135: Use multiple inheritance to represent multiple distinct interfaces.

Possible Messages

Key

Text

Severity

Disabled

multiple_inheritance

Use of multiple inheritance.

None

False

Options

consider_special_members_on_interfaces

consider_special_members_on_interfaces : bool = True

Whether to require special member functions on interface classes to be pure virtual or deleted.
 

ignore_pure_interfaces

ignore_pure_interfaces : bool = True

Whether C++ interfaces are allowed, i.e. classes with only pure virtual members.