<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/59051>59051</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format mis-indents lambdas with sufficiently long signatures
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
brevzin
</td>
</tr>
</table>
<pre>
My `.clang-format` looks like this:
```
BasedOnStyle: llvm
AccessModifierOffset: -4
AlignEscapedNewlines: Right
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: true
AllowShortLambdasOnASingleLine: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BreakConstructorInitializers: BeforeComma
BraceWrapping:
BeforeElse: true
BeforeCatch: true
BeforeLambdaBody: false
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
IndentWidth: 4
LambdaBodyIndentation: Signature
NamespaceIndentation: None
PenaltyBreakAssignment: 60
PenaltyBreakBeforeFirstCallParameter: 175
PointerAlignment: Left
QualifierAlignment: Custom
QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile']
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: true
SpacesBeforeTrailingComments: 2
SpacesInSquareBrackets: false
```
which produces this indendation:
```cpp
template <typename T>
struct Optional {};
namespace abcd {
struct SufficientlyLongName {};
} // namespace abcd
struct X {};
struct C {
auto format(X const& x, auto& ctx const) {
auto some_very_long_name =
[&]() -> Optional<abcd::SufficientlyLongName const&> {
if (true) {
return {};
}
else {
return {};
}
};
return 42;
}
};
```
The body of the lambda should be indented with respect to the signature of the lambda, that doesn't happen in this case - which looks weird and there doesn't seem to be any option to fix it. The desired indentation would be:
```cpp
struct C {
auto format(X const& x, auto& ctx const) {
auto some_very_long_name =
[&]() -> Optional<abcd::SufficientlyLongName const&> {
if (true) {
return {};
}
else {
return {};
}
};
return 42;
}
};
```
With the `};` of the lambda also indented.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlVltz6jYQ_jXmRQMDNmB44IFLMpNpTkhLOjlvGdleYxVZciU5hPPrz0q2wVxyTjttn-phjO39drWXb1eKZHKYfTkQb9zvxZyKbTeVKqcG3wmXcqcJZzsgJmPaC-Zef-X1m_u4X__c64JqSNZiYw4cEEk4f8_b8Hkcg9ZfZMJSBmqdphqMxXWHtZyzrbjTMS0geYI9ZwLsiuQ3ts1MA-Fyj7dnqmgOBpRepytArxU1TIq1eIIP84iKVi-lXENLb5NJZRZcxju9FvMNE1sOP8TelyK2Zq_hRpVX6EeaRwn9MXZPD3qhgO5eIC84NdByXp-DF0w803g3V9syB2H0hZe1-JSIS7ldZQFYSlgoGleZXJbayLwFWOKyuGRspHoQzDDK2bfaVqW7lHlOGwU086poUWB4RyaQGnhnVz4LoJEsqYmz26IqZQsk4IX3S8nLXDyynDmGTPrN51vuYgnWWHqX8LXCh2dQ18l_EAmm8ZUlxjlTc-7kQSV3lbDyDXKRmlLV2k-YZV1gAi5gT1LUiGcQlJuDS-tca1S3ZbOYpj_aiCr-e6a0WdIWny1-EI5qBcmEsfG1jD1CWvfCryWGbzvpTN4u8RGxVkll2hstPD9kwvYWPnj-kuCftvHEp3dzKFrS2Cb99PoukbeMO8BoVS20Qfo_iJiXCVyw2Ep-10iYz4m-sWmdpxjo0o2OJdXmM0TTNr_AYS9VcgOmq8y-KMowyK3lb9M9fhv2IDZ_lrRqjh1ctdfFaKvu-4zFGSmUTEq04CYiYZYPScOHm9MxLorqi6m9J16wtDkWWHPy4gV3lbiiNlkX1hjlxAsXXrjygkXbqmiISGgUJw7TVt6UacpihiHzw6MUW8vbK0PhimAl7_FHzs21F6oNfr3tRi1dnhwgeNHSSFLvHv7kK6mpMyYfljxWal9i89FIpuf6Rxta5vD2DurwxjGI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