1.. title:: clang-tidy - readability-redundant-member-init
2
3readability-redundant-member-init
4=================================
5
6Finds member initializations that are unnecessary because the same default
7constructor would be called if they were not present.
8
9Example
10-------
11
12.. code-block:: c++
13
14  // Explicitly initializing the member s is unnecessary.
15  class Foo {
16  public:
17    Foo() : s() {}
18
19  private:
20    std::string s;
21  };
22
23Options
24-------
25
26.. option:: IgnoreBaseInCopyConstructors
27
28    Default is ``0``.
29
30    When non-zero, the check will ignore unnecessary base class initializations
31    within copy constructors, since some compilers issue warnings/errors when
32    base classes are not explicitly intialized in copy constructors. For example,
33    ``gcc`` with ``-Wextra`` or ``-Werror=extra`` issues warning or error
34    ``base class 'Bar' should be explicitly initialized in the copy constructor``
35    if ``Bar()`` were removed in the following example:
36
37.. code-block:: c++
38
39  // Explicitly initializing member s and base class Bar is unnecessary.
40  struct Foo : public Bar {
41    // Remove s() below. If IgnoreBaseInCopyConstructors!=0, keep Bar().
42    Foo(const Foo& foo) : Bar(), s() {}
43    std::string s;
44  };
45
46