47 lines · plain
1.. title:: clang-tidy - readability-redundant-member-init2 3readability-redundant-member-init4=================================5 6Finds member initializations that are unnecessary because the same default7constructor would be called if they were not present.8 9Example10-------11 12.. code-block:: c++13 14 // Explicitly initializing the member s and v is unnecessary.15 class Foo {16 public:17 Foo() : s() {}18 19 private:20 std::string s;21 std::vector<int> v {};22 };23 24Options25-------26 27.. option:: IgnoreBaseInCopyConstructors28 29 Default is `false`.30 31 When `true`, the check will ignore unnecessary base class initializations32 within copy constructors, since some compilers issue warnings/errors when33 base classes are not explicitly initialized in copy constructors. For example,34 ``gcc`` with ``-Wextra`` or ``-Werror=extra`` issues warning or error35 ``base class 'Bar' should be explicitly initialized in the copy constructor``36 if ``Bar()`` were removed in the following example:37 38.. code-block:: c++39 40 // Explicitly initializing member s and base class Bar is unnecessary.41 struct Foo : public Bar {42 // Remove s() below. If IgnoreBaseInCopyConstructors!=0, keep Bar().43 Foo(const Foo& foo) : Bar(), s() {}44 std::string s;45 };46 47