readability-redundant-member-init¶
查找由于成员初始化不是必需的,因为如果它们不存在,将调用相同的默认构造函数。
示例¶
// Explicitly initializing the member s and v is unnecessary.
class Foo {
public:
Foo() : s() {}
private:
std::string s;
std::vector<int> v {};
};
选项¶
- IgnoreBaseInCopyConstructors¶
默认值为 false.
当设置为 true 时,检查将忽略复制构造函数中不必要的基类初始化,因为某些编译器会在复制构造函数中未显式初始化基类时发出警告/错误。例如,具有
-Wextra
或-Werror=extra
的gcc
会发出警告或错误base class 'Bar' should be explicitly initialized in the copy constructor
,如果在以下示例中删除了Bar()
// 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;
};