<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143218>143218</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Wrong linkage and mangling for class-scope lambda expressions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zygoloid
</td>
</tr>
</table>
<pre>
C++ allows lambdas to be defined directly in class scope. When this happens, the lambda should have the same linkage as the class, as it would if it appeared in a default argument or default member initializer or function body within the class, and it should be mangled [with the enclosing class as the mangling context](https://github.com/itanium-cxx-abi/cxx-abi/issues/165).
Example:
```c++
template <auto L> struct B {};
struct A { B<[] { return 0; }> b; };
void f(decltype(A::b) x) {}
```
This should result in an external linkage symbol for `f` being emitted. But Clang incorrectly gives the lambda internal linkage and a mangling involving `$_3`, resulting in no definition for `f` being emitted.
GCC appears to have implemented this in version 15 onwards. (In version 14 and before, GCC used internal linkage for the lambda, as Clang does.)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8VE2P4zYM_TXMhUigyHYSH3xIMpuiQI8F9lhIFmOrlaVAkvOxv76g7c7MDtAFgkim-PGo9yiVku08UQPVCaq3lRpzH2Lz49UFF6xZ6WBezRnkCeQJlXPhkdCpQRuVMAfUhIau1pNBYyO12b3QemydSglTG260we89ecy9Tdir2418AnnG3NOSB1MfRmewV3eazEkNhM76f1RHyGV6mhNynEpoMz6mCHvlPedUkQzXVYxGjS6jit04kM8Y4rttoEFTROtttsrZHxT59Dr6NtvgkVvFh8299V9qesOFFpyacFC-c2QQqhP7T97kWxeS9d3S_AJ8cp2swWd6ZqjeQB76nG8JiiPIC8hLZ3M_6k0bBpAXm5W347Bun8-10hbk5WNnUxopgbxsdxXIegPiCOL47amGmyNOJ46wE_OvnTkDccw03JzKhFCc1ZgD_gHFN0w5jm3GE8L-BPs3KNh1MR7ZiCcozrMqps9IeYweBRQc88Y59Pueg-_BGryCPBhqXX7dCOThyKiKowZZ45P_lmqfgII4_sniWK43UmKumEyP9MwUvXLvckivQQeH1xARduIKO4Ga-HppsDmT2eBpzHh2yndofRviosnO3il9Fp31XzIzyeqDLuvvwd15xxBl-VcxrecF3-yCPszyt5OA_h_VTNRv5_Oi1ml2JsFbpo6FSmaeEevxTjFxvm2FwT9UNGmDIA-_fzopJ7yariESo-LUY5qG4EtfDOqj72WE5gsygdIGZL0yTWHqolYrarb7spZVWe_2q76pq-2WdvX1oHd7qkmbrZBUtVLrttbbg1zZRgpZiZ3YCyFqud_QtdKtkWJXGl0eSgmloEFZt3HuPmxC7FaThpttWcjtYeWUJpemt0dKTw-cTkFKfopiw0FrPXYJSuFsyukjTbbZUfM9Bt_9ROE7gdz3NInr6Rn6j3d63iIlvsS0GqNrfjGJXGtZ1rcY_qY2_zSDcwv3Rv4bAAD__7SZu28">