Rule A12-1-6 (required, implementation, automated)

Derived classes that do not need further explicit initialization and require all the constructors from the base class shall use inheriting constructors.

Rationale

Reimplementing constructors that do not need further initialization is error-prone and may lead to using wrong base class constructor accidentally.

Example

// $Id: A12-1-6.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $

#include <cstdint>

class A
{
public:
A(std::int32_t x, std::int32_t y) : x(x + 8), y(y) {}

explicit A(std::int32_t x) : A(x, 0) {}

private:
std::int32_t x;
std::int32_t y;

};

// Non-compliant
class B : public A
{
public:
B(std::int32_t x, std::int32_t y) : A(x, y) {}
explicit B(std::int32_t x) : A(x) {}
};

// Compliant
class C : public A
{
public:
using A::A;
};

See also

C++ Core Guidelines [11]: C.52: Use inheriting constructors to import constructors into a derived class that does not need further explicit initialization.