Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.CTOR.BASE

Constructor does not explicitly call constructor of its base class.

MISRA-C++ Rule 12-1-2 (advisory): All constructors of a class should explicitly call a constructor for all of its immediate base classes and all virtual base classes.

Rationale

This rule reduces confusion over which constructor will be used, and with what parameters.

Example

class A
{
public:
   A ( )
   {
   }
};
class B : public A
{
public:
   B ( ) // Non-compliant — benign, but should be B ( ) : A ( )
   {
   }
};
class V
{
public:
   V ( )
   {
   }
   V ( int32_t i )
   {
   }
};

class C1 : public virtual V
{
public:
   C1 ( ) : V ( 21 )
   {
   }
};

class C2 : public virtual V
{
public:
   C2 ( ) : V ( 42 )
   {
   }
};

class D: public C1, public C2
{
public:
   D ( ) // Non-compliant
   {
   }
};

There would appear to be an ambiguity here, as 'D' only includes one copy of 'V'. Which version of 'V"™s' constructor is executed and with what parameter? In fact, 'V"™s' default constructor is always executed. This would be the case even if 'C1' and 'C2' constructed their bases with the same integer parameter.

This is clarified by making the initialization explicit, as in:

D ( ) : C1 ( ), C2 ( ), V ( )
{
}