AutosarC++19_03-A10.1.1¶
Class shall not be derived from more than one base class which is not an interface class
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
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 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#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 [8]: 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 [9]: 10.3.1 Ensure that a derived class has at most one base class which is not an interface class.
- C++ Core Guidelines [11]: 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¶
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
consider_special_members_on_interfaces¶
consider_special_members_on_interfaces : bool = True
ignore_pure_interfaces¶
ignore_pure_interfaces : bool = True