<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54798>54798</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-format] Misformatting lambda auto trailing return type
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          0xjc
      </td>
    </tr>
</table>

<pre>
    The following code:
```
#include <variant>

namespace xyz {
template <typename... Ts> struct Visitor : Ts... { using Ts::operator()...; };

struct MyTestClassFoo {};
struct MyTestClassBar : public MyTestClassFoo {};

MyTestClassFoo& f(std::variant<MyTestClassFoo, MyTestClassBar>& v) {
  return std::visit<MyTestClassFoo&>(
      Visitor{[](MyTestClassFoo& s) -> auto& { return s; },
              [](MyTestClassBar& t) -> auto& { return t; }},
      v);
}
} // namespace xyz
```

gets misformatted to:
```
#include <variant>

namespace xyz {
template <typename... Ts> struct Visitor : Ts... { using Ts::operator()...; };

struct MyTestClassFoo {};
struct MyTestClassBar : public MyTestClassFoo {};

MyTestClassFoo& f(std::variant<MyTestClassFoo, MyTestClassBar>& v) {
  return std::visit<MyTestClassFoo&>(
      Visitor{[](MyTestClassFoo& s) -> auto& { return s;
}
, [](MyTestClassBar& t) -> auto& { return t; }
} // namespace xyz
,
      v);
}
} // namespace xyz
```

under `.clang-format`:

```
BasedOnStyle: LLVM
PointerAlignment: Left
```

Tested that this bug occurs with clang-format 12, 13, and 14.

This issue does not occur if the `auto&` trailing return types are replaced with specific types.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztVEtvozAQ_jVwGRURDCQ5cMhjc2q1K23VuzGGuDIY2aZt9tfv2IQ82qi70mpvRZZ5zMw3n2e-oVTVoXjcc6iVlOpVdA0wVfGArIJ4G8SrII-Pa3xNiOiYHCoOAdm8UC1oZwPy7Wj1e0dbbnrKOLwdfkEwX4-fLW97Sa0PtIeeO7coiuDRYDwYqwdm4UkYYZVGnxUanBnjYTCOl3Nc4VI91xSdgmQRJEv0Ccga3bZ4u6RxRHw4PHJjN5Ias1PK07lw_ei0pmP2fiilYH8IH_drnyDJoUZuxlYj31OVNu8dN-8Su0Ji9Ase61w3AM3toDs4A7oi3YDLffxiCnPXsZ4OLMO1RfNHtsblu3NdoIP1X1zRp6xTdZPNJfB03YJ1J0EQ-xmsnWA_ILvTnwuM5ukBgmSHC670dVulfm-4NdAKUyvdUmt5BcjiS9dfuj7p-r3GkPg_6_lv1PqfBD90Fccm53HEJO2au1H4zumk-lvBa2p49b37aQ_S_ffh_v7pYbT8UKKzXK-kaLqWu1ajldf2Ew6uaG7S9tTiJgyUQwOKsUEbeBV2D5fUYJa4ms-I22lXwSyNrsAcgDBm4FApbqBTdsQCUSM6d2c99gKfwGoqpJuoqSc4jQao5vgBR5QhL0_B9JyJGofAO0RhVZBqSZY0tMJKXqAEruqXbeHh9Bdx8JK2ZUW9Cm7mDActi721vR9s38MG8w5lxFSLL1K-TLe7XqtnzlBaO39OlOwuS-fLRbgvakayNE9n6TLNkpQssySrFoTkWU1m5aKsQ0lLLo3jGyRJx1_HUuEzUg5FkcRJEqfxfJZlOUmjNGVzktNZPafLbEHrII15i-QjxyNSugl14SlhxwwapTDWnI04B6gC7svj8PH0e6WL-O2ZhT5v4Xn_Bvr-ci8">