<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/94181>94181</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format incorrectly indents lambda trailing return when lambda has constexpr specifier or noexcept specifier without expression
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
carljohnson93
</td>
</tr>
</table>
<pre>
.clang-format:
```
BasedOnStyle: Google
```
Here is the formatted code when lambda doesn't have constexpr/noexcept specifier:
```c++
#include <type_traits>
void very_long_function_name_yes_it_is_really_long(...);
void do_something(...);
int main() {
very_long_function_name_yes_it_is_really_long(
[](auto n)
-> std::enable_if_t<
std::is_arithmetic<decltype(n)>::value &&
!std::is_same<std::remove_cv_t<decltype(n)>, bool>::value> {
do_something(n * 2);
});
}
```
As expected trailing return arrow is indented 4 spaces after the lambda. But adding constexpr or noexcept specifier after lambda makes it 0 spaces:
```c++
#include <type_traits>
void very_long_function_name_yes_it_is_really_long(...);
void do_something(...);
int main() {
very_long_function_name_yes_it_is_really_long(
// also happens with constexpr specifier
[](auto n) noexcept
-> std::enable_if_t<
std::is_arithmetic<decltype(n)>::value &&
!std::is_same<std::remove_cv_t<decltype(n)>, bool>::value> {
do_something(n * 2);
});
}
```
Somewhat surprisingly, this issue doesn't happen when noexcept specifier with expression is used (e.g. `noexcept(true)`).
clang-format version: 17.0.6
OS: EndeavourOS Linux, kernel 6.9.3-arch1-1
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVc2O4ygQfhpyKcXCkMT2wYf0T3YPK_WhH8AiULGZwWABTnfefoXtTSfTPaPd8w5CiQxVH6WvvqoSIejWItZk-0C2Tysxxs75WgpvvrnOBmcrvjo6dakzaYRt1yfnexEJ3xP6ROie7Oiyp88HEVC92Nd4MUj4Hv5wrjX4pen8-yd6BB0gdggzdEQF0imEtw4tGNEflQ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