<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58436>58436</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format]: Cannot align declarations in lambda when initializing lambda with uniform initialization.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
aleksanderostrup
</td>
</tr>
</table>
<pre>
In modern C++ we like to have a uniform initialization of our variables. For this we uses the {} syntax.
However, when using this to initialize a lambda function with variable declarations, we get wrong formatting:
I have reduced the error to the following minimum example:
`
.clang-format
---
Language: Cpp
AlignConsecutiveDeclarations: Consecutive
Cpp11BracedListStyle: false
`
And a cpp file:
```cpp
#include <mutex>
void SomeFnc() {
auto const callback{ []() {
std::mutex m;
std::scoped_lock lk{ m };
} };
}
```
Formatting with the above .clang-format gives:
```
#include <mutex>
void SomeFnc() {
auto const callback{ []() {
std::mutexm;
std::scoped_locklk{ m };
} };
}
```
I.e., it removes the space between the type and the identifier. This produces uncompilable code.
A short-term fix is to initialize without {}. This produces:
```
#include <mutex>
void SomeFnc() {
auto const callback = []() {
std::mutex m;
std::scoped_lock lk{ m };
};
}
```
But a {} style would be preferable to stay consistent in initialization.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNVcuO6zYM_Rp7Q8TwI85j4cUkadAB7u52X8gy7agjS4YeyaRfX0qeSZOZAe4F2gI1jNgyJfLwkDxpdXdtnhWMukOjYJ-UO7rhgiDFC4LTcGJnBAZeiV6bEYQSTjAp_mROaAW6B-0NnJkRrJVoMzhqA-4kbPDhLVpaICTrXbI-gL0qx16zJD8k-dOv-oJnNEm5h8sJFW0WapiPUthbnBBcsrHtGPRe8Rj1ItzpFhM65JKZiMdGbwgDOrgYTf4CaOYcuU6qpznw_Ps8Z2aw8xy7iBKNCeB1XPRaSn0JkEbCMvoR8JWNk8QPfpJVPr9khEINizng_Gm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