<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/90235>90235</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] `readability-redundant-member-init` vs `-Wmissing-field-initializers`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dieram3
</td>
</tr>
</table>
<pre>
I just came across an incompatibility between the new `readability-redundant-member-init` check and the `-Wmissing-field-initializers` diagnostic. It is a common pattern to have an aggregate type representing a set of options, some of which are optional, e.g.:
```cpp
struct options {
int required_1;
int required_2;
std::optional<int> optional{};
};
```
Now if I have the following:
```cpp
void foo(options opts);
void bar() {
foo({
.required_1 = 4,
.required_2 = 2,
// optional omitted.
});
}
```
`readability-redundant-member-init` will complain the initializer for `optional` is redundant. However, if I remove it, `-Wmissing-field-initializers` will complain that the field initializer for `optional` is missing.
Compiler Explorer repro: https://godbolt.org/z/xfzPv8h47
Is there a way to make these two agree? Or maybe `readability-redundant-member-init` needs a new option or adjustment?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE2T4jYQ_TXi0oVLyMaGgw8zw1KZS5Jbjqm21djalSVHamCZX5-SPQPMpjYLRdmu_tLrp9eNMZrOEdVi_SzWuwUeufeh1oYCDvmi8fpSv8LXY2RocSDANvgYAR0Y1_phRDaNsYYv0BCfiRxwT-DoDKKUgVDj7F4G0ken0fFyoKGhsDTOsCgltD213wCdnjJFKZd_DSZG47rlwZDVU6BBa94oxJSgDXbORzZtBq8MJgJC64fBOxiRmYID9tDjiRJM7LpAHTIBX0aCQGOgSI6N6wAhEoM_gB_ZeBeFeoHoB0qmc2_aHjDQuxNt8lLWZSJ_EnIn5MezlPO_HcfZEjkcW_4oCqJ6nu0AAMYxBPrnaALpv1ci_5lLfXJF1unU_OmKJX8xjkX-5YauehbV7pr16fsD4T3s3_0ZzAFeZ6IS9QdvrT8b1_2ywZM3Gg7eC7X5aNKPHIXa3s68BTYYhNoItf3MxJz_yZR-2Y0dEPkOCqFefhahpgj1nwih9kLtr9SAHwwz6ew9KnFzD7Xa_Q9Pj8r4bKxNMhwtmnkI7nQLBx-StK-XVcqk22uxDH7zZzpRSBqbbiXQ4E8EhpPlgaH48Xjk-U5T8ANI3otn952_-GE0lgJ8-T5aHyhMw-NF_gQ98xiTTCaiO68bbznzoRNq_ybU_vvh7c_Tpi-q-3qvMUEKBAhnvKQZHfDbJL1IwGcP2AUike_hjwADXhp6eIc4Ip3WQNo7c2fgA6BOe2ugNCj7ha5zvc23uKB6Va2K1VqWq82ir1cVbtU2p0KXm2qz3sgttYjbstQoqZHtwtRKqkIWqlyV63K9yeSmWB2aqi1yWcl2tRaFpAGNzaw9DYmFhYnxSPVWqny9sNiQjdN-Vaq16LolG30RSqV9G-qUtGyOXRSFtCZyvJVhw3bazHdp693DrJziI8pZHIOtf7hQw_2xyVo_CLVPaN5fyzH4r9SyUPupwyjUfmry3wAAAP__RAP53Q">