<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/134440>134440</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-tidy] readability-redundant-member-init fails to account for explicit user-provided default constructors
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          connorsmacd-hh
      </td>
    </tr>
</table>

<pre>
    The `readability-redundant-member-init` check issues warnings on initializers even when the relevant default constructor is **marked `explicit`** and is **user-provided**.

Example code ([godbolt here](https://godbolt.org/z/YPqKPvGz1)) with clang-tidy args `-checks=-*,readability-redundant-member-init`:

```C++
struct A
{
 explicit A() {}
};

struct B
{
    A a1 {}; // Compiles, but tidy detects a redundant member init
    A a2; // No warning from tidy, but does not compile
};

auto b = B{};
```

In the above example, clang-tidy flags the `a1` line with:

```
<source>:8:10: warning: initializer for member 'a1' is redundant [readability-redundant-member-init]
    8 |     A a1 {}; // Compiles, but tidy detects a redundant member init
```

When I do what tidy wants in the `a2` line, this fails to compile with:

```
<source>:12:12: error: chosen constructor is explicit in copy-initialization
   12 | auto b = B{};
      | ^
<source>:3:14: note: explicit constructor declared here
    3 | explicit A() {}
      |              ^
<source>:9:7: note: in implicit initialization of field 'a2' with omitted initializer
    9 |     A a2; // No warning from tidy, but does not compile
      |       ^
1 error generated.
Compiler returned: 1
```

Interestingly, clang-tidy no longer warns if the constructor is instead explicitly defaulted, i.e., `explicit A() = default;`.

For context, I encountered this issue when working with `boost::circular_buffer`'s default constructor ([docs here](https://www.boost.org/doc/libs/1_87_0/doc/html/doxygen/boost_circular_buffer_c___reference/classboost_1_1circular__buffer.html#doxygen.boost_circular_buffer_c___reference.classboost_1_1circular__buffer_1a00b4cb2a7dd9c100008c05ba18c43575)):

```C++
explicit circular_buffer(const allocator_type & alloc = allocator_type()) noexcept;
```

It seems to me that `readability-redundant-member-init` should ignore instances where the initializer is invoking an explicit default constructor. Is that correct or am I doing something wrong?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVk-P46gT_TTkUkqEsZ0_hxySzuSn1k9azWGl1Z4iDGWbHQxZwElnPv0KHCeZTM9MS7utdIeGonj16hUF9141BnFNyi0pdxPeh9a6tbDGWOc7LuS0bSeVlZf17y0CmVOHXPJKaRUuU4eyN5KbMO2wq9BNlVGBzCmIFsUXUN736OHMnVGm8WANRAPFtfqKzgOe0MC5RQOhRXCo8cRNAIk173UAYY0PrhfBOlAeCNsQtum4-4IyAsG3o1YinTcsATfybth7dNOjsyclUQ5TM0I3hG4-vfHuqBGElQiELUm5baysrA7QokNS7ghbtiEcPck3hO0J21_XZ9Y1hO2_Erb_8_Pf__98-t_XjLAVYSs4q9CC0Nw006DkBbhrfEQ5TVR4ku-mCcTLR_iL5yaocZw-L4Rt44duBkogrS7iBIxEwCYGw1YQ5xe7ZLAj-XZwdd23ve8DgA3wbDTPtzAECy-2OyqNnrAXqPoAKSCJAUXwwOGGGgbUKal3h-zB0292zD7UznbJ0-hVWvRgbMxzOu4JL--DhQpIvoPtDeEjJYPZ6yAeXtkTAg6ZjSc8pKLWvPHJiswpz6I-tTKYUvY903Gcv3jbO4Ek_0TyzZLkmyzmZIwlDh-EDLV1IxWELXhG2CLq8M4TKbe_Tnu5u3K4BLJ4gf88PU_E_RHr7hWkhXPLr07O3AQPytzIYiNZ8azQKg81V9pDsGPWPsxixsY_gM5ZFweitR7Nc6Hf9Kzi0vEyvXHNg7JmYCljiaUfqSTRlyxI-el7MHnEUkQIxgZMmMZDH8FIFJo7lMO9MHjNk9cf19z95G9-3oWxIvlm8YhCGVDdLfrHqMHWUCvUMkmMRYmlK8d2KgSUj3q8glg9yuhfFOVzQEMk2ZBFaNCg4wFlvFyvynTgMPTOoIwxZe8VbUCHPijT6MtTtRoL2poGXQLpQdVJjU8aUcYH5PKWB30Z20a87F9AzXAW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