<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/97242>97242</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] bad formatting of entire constructor definition when first member initializer uses trailing comma
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jacobsa
</td>
</tr>
</table>
<pre>
When the first element of a constructor's member initializer list is initialized with braces and uses a trailing comma, clang-format won't format the constructor definition at all. For example, it leaves this bad formatting as-is:
```c++
MyClass::MyClass()
:foo_{MakeFoo(),}, bar_{MakeBar(),}, baz_{MakeBaz(), }{}
```
It's only the first element though. If you change that one to use parens, it formats the entire definition well, including the other initializers that use trailing commas:
```c++
// Before
MyClass::MyClass()
:foo_(MakeFoo()), bar_{MakeBar(),}, baz_{MakeBaz(), }{}
// After
MyClass::MyClass()
: foo_(MakeFoo()),
bar_{
MakeBar(),
},
baz_{
MakeBaz(),
} {}
```
I would hope that the original example would be formatted similarly, even with the trailing comma in the first initializer:
```c++
// Desired outoput
MyClass::MyClass()
: foo_{
MakeFoo(),
},
bar_{
MakeBar(),
},
baz_{
MakeBaz(),
} {}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU2PozgQ_TXmUuqImBCaA4dOR5HmMOc9rgoowLPGjuyis-lfvzKQbsj0aLqlPQxCJFAffq73XIXeq9YQFSI9iPQY4cCddcUPrGzpMSptfS3-6sgAdwSNcp6BNPVkGGwDCJU1nt1QsXVCZh566ktyoIxihVq9kgOtPIPyi281XBR3UDqsyAOaGgYf_gA7VFqZFirb9yjkM1QaTfvQWNcjw8UaITOG-TVAWqwPNTXjGtYAMqDWGzhZB_Qv9mdNIZti0IQv5IE75aHEes7FYVH0D8qL5EnERxHfnvt4uishD-Eev36_Pmv0o2_y9iIfhcwnOwCASJ4aa_8W2eE7_kMna2cH-SyyYwBTortZD-h-tr6-W1_frDBfwSs7hOca5hL7Nx4psUZfP6CPOzu03Qa-NXC1A1QdmpaAO2SwhoBtIAXO6Mj4uXZTrfyYjAwrR8uaX0jr0dFUeqhDQYOf5W6tBz-tEZKv6f5c6YU8CXmCAzXW0SfZuFEhH--oyP93HpYYnxom9yXBwK9hvvvBDfH86SfgC89pE-vY10Xs23W_v7sk8HuxwcUOuobOnmcVjew71SqD-nYIZ6eSbueOavCqVxqdvoay0guZqTuE8LVAQC3b0EJSXxHOkbxyVIMd2J4H_ryCYD7NH1Vudbp_U_4_g7qoLpI6T3KMqNhm2zzLt4_bLOqKuNxmeZpgnFU1NVQme0ybbdI05S5-rCuKVCFjuYv3SSyTdJ9mmzhLt3Epm7rK0ior92IXU49Kb7R-6TfWtZHyfqAiz-RORhpL0n4cN1Iuu7uQMgwgV4Swh3JovdjFYXb490SsWI-jahWYHu87uW1u_ekX8-ESRtqkow8m1jiN1tqLBqeLjvk8imSUUqu4G8pNZXshTwHi_PNwdvYHVSzkady4F_I07f2lkP8FAAD__7rgMEs">