<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/85495>85495</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang accepts invalid conversion of lambda to std::function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ranaanoop
</td>
</tr>
</table>
<pre>
The following program compiles with clang without any diagnostic but rejected by gcc: [Demo](https://godbolt.org/z/79hrndn3E)
```
#include <functional>
#include <iostream>
#include <string>
int func()
{
return 5;
}
int main()
{
std::function<const int&()> getter1 =
[] { return func(); }; //gcc rejects but clang accepts
getter1();
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0Um2OozAMPY35Y00FCSnlBz_aYTjBXiBfhaxCUiVmRrOnX0GZVju7KyHiyHn2s9-TObsxWNuBuIDoC7nQFFOXZJAyxHgrVDSf3Y_J4jV6Hz9cGPGW4pjkjDrON-dtxg9HE2ovw7iFcSGU4RONk2OImZxGtRAm-9NqsgbVJ45aAz8jiEtv5wiiB3aaiG4Z-BnYAGwYo1HR0yGmEdjwC9jQtFMKJvA3YC2UPZTn_X8s9-9-ZdwF7RdjEfjrdQmaXAzSA3_71wMXMyUr5_-kMyUXxkfSBcK1JLATsBZ3RHPZI0TEZGlJAQXwyyPfP9GzdGFHP-FP9B5lMusm-PmLP_BXHUMmdIGAHe8VgL_haIlsqhB4_wW-S4krrZ3Mk_LGqum3475nrXdl8qbSXUaptb1RfvDZuzxqfBvsIUFhOm5a3srCdlVTleLIWFUXU9cwK4w9XnVzretaHGvTirayqqkUa4w-Fa5jJatLXh3Luiqr-sAb0chWXiupVCVMC3VpZ-n8wfv3ebVF4XJebHcSdSsKL5X1eXMxY9sMwNhq6NSt71_UMmaoS-8y5WcFcuRt9_rHyC68S-8M6hjebcouBoxX9HJWRiLFv6XBYkm---ZeR9OiDjrOwIa13X683FJcdw1s2NhnYMM2wO8AAAD__x0rDms">