readability-redundant-member-init¶
Finds member initializations that are unnecessary because the same default constructor would be called if they were not present.
Example¶
// Explicitly initializing the member s is unnecessary.
class Foo {
public:
Foo() : s() {}
private:
std::string s;
};
Options¶
-
IgnoreBaseInCopyConstructors
¶
Default is false.
When true, the check will ignore unnecessary base class initializations within copy constructors, since some compilers issue warnings/errors when base classes are not explicitly intialized in copy constructors. For example,
gcc
with-Wextra
or-Werror=extra
issues warning or errorbase class 'Bar' should be explicitly initialized in the copy constructor
ifBar()
were removed in the following example:
// Explicitly initializing member s and base class Bar is unnecessary.
struct Foo : public Bar {
// Remove s() below. If IgnoreBaseInCopyConstructors!=0, keep Bar().
Foo(const Foo& foo) : Bar(), s() {}
std::string s;
};