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

    <tr>
        <th>Summary</th>
        <td>
            [libcxxabi][ItaniumDemangle] Mangling produced by clang for lambdas with template parameters fail to demangle
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            libc++,
            libc++abi
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          Michael137
      </td>
    </tr>
</table>

<pre>
    Take this example:
```
int main() {
    auto foo = [](auto) -> int {
 return 50;
    };
    foo(50);
}
```
With top-of-tree clang this mangles to: `_ZZ4mainENK3$_0clIiEEiT_` which the `llvm-cxxfilt` fails to demangle. Stepping through the code, the failure occurs in `parseTemplateParam` (when parsing `T_` at the end).

The problem was introduced in the (de)mangler changes in https://reviews.llvm.org/D147655. Specifically, it added a [`SaveTemplateParams` to `parseLocalName`](https://github.com/llvm/llvm-project/blob/79b03306af5c11d354fa90db8bfd7818cd811ef5/libcxxabi/src/demangle/ItaniumDemangle.h#L2951-L2953), which resets the `TemplateParams` when we're done parsing the name. This trips up `parseTemplateParam`.

GCC mangles the above to `_ZZ4mainENKUlT_E_clIiEEiS_`, which demangles fine. The difference here is that GCC mangles the name as a `<lambda-sig>` (i.e., `Ul`), whereas clang mangles the lambda as an unnamed struct with internal linkage. The difference between a local unnamed struct and a lambda is that lambdas can have template parameters. Maybe this difference was looked over in `D147655`?

@zygoloid @urnathan 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVV9vo7gX_TTOy1UiYyDAQx6mTfPT6DczWqkdrTQv1cW-BO8YG9mmaffTr0xIm05nH1aKCBh87p9zzjWGoI-WaMfKG1buVzjF3vndVy17JJPl1ap16mX3gD8JYq8D0DMOoyGWf2J8z_gntuXLb37UNsKA2jJRM9EAq27O6wAAOEUHnXPA8j2c4zFRp9X06Zrld5C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