<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/77618>77618</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-tidy] Create check to enforce usage of designated initializers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy,
check-request
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
PiotrZSL
</td>
</tr>
</table>
<pre>
Info: https://en.cppreference.com/w/cpp/language/aggregate_initialization
Code like this:
```
struct A
{
int a;
int b;
};
void test()
{
A v{10, 20};
}
// should be changed into:
void test()
{
A v{.a = 10, .b=20};
}
```
Rationale: It's very easy to introduce bug when adding some field in middle of struct, or changing order of fields, with this we can always be sure that such objects are constructed correctly.
Check name: modernize-use-designated-initializers.
Check should enforce that all aggregates should be initialized with designated initializers.
There can be config to ignore aggregates that have only 1 argument.
There can be config to reduce check to only trivial types, in such case it could be used on older standards with compiler extensions.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE1v4zYQ_TXUZWBBohwpOuiQxDCwQA9F21MvxYgcSexSpMsPu95fX5ByEhvtFgsYNMUR5817bzTovZoN0cCeXtnTocAYFuuGn5UN7vdffypGK6_DFzNZ1rzAEsLJs-aF8SPjRzKlOJ0cTeTICCqFXRk_Xhg_itOJ8aNGM0ecifEjzrOjGQP9oYwKCrX6hkFZw6oDq1629c1KAq2-EoRFZZQt2Fa3X370wUUR4D3YvW4bAFAmALLm8WD8OGDd4XOf17NVEgL5wPgz4_2_M77AmXWvdcX4G_DqIUF3uG2yEuAXG7WEkUAsaGaSCdx-cPhBpBKBNQfYAMuRNYfvoT5qsq2_ZEVRU3LqS2C883AmdwVCf4VgU0nOyigIxjjDZSEDKKUyM3i7EkyKdKobViWlJrATbGKnaqzbmKW3rZPkUjjf8Cl8UWHJtsGFQKAB1Be8-iSIjy45igF8FAvY8U8SwQM6AmHNhkAShHWORNDX8qEnFhJfweCaSa1WkjPqG-2ip52k1LkYSO4-moqcL-9v3nwhM1knbmWg1vDRj_7Ous8sciP0iQD_gfDbQm4jO2Yqk5qzyrOxju4RMuqCZwJr9BVqQDfHlUz4_0SOslciEwl2uxycOivUEK4nysors-kq0BOoAOKdTfQkwRqwOrnlAxqJTvqNmbDrSWlyQH8HMl5Z48tCDo3smx4LGuqu2vdV0_dVsQz7J6Inzqepneq-EV3fdNOeSLZ93baIz4UaeMX3VV1Xdcvbpirbvp6ahu8F9SN2XLJ9RSsqXWp9Xkvr5kJ5H2nourZ-LjSOpH0eQJyLNDV2Qckr45zxt3SUFNg5-ivmL4inMeWGlGo3xtmzfaWVD_4zeVBB54F2l-zpAG-OMNwJ-t4V0eOc2_07fhfR6eFx9M0qLHG8TbyEe_vbnZxN_c34MTP0jB8zyX8CAAD__7kbuZs">