<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96428>96428</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Strange behaviour with lambdas returned from module exported member function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kamrann
</td>
</tr>
</table>
<pre>
The following code leads to some somewhat unintuitive error messages, and has some behaviour differences in comparison to gcc.
```
export module mod;
export struct s
{
/*inline*/ auto make_lambda() const
{
return [/*this*/]{};
}
};
```
```
import mod;
int main ()
{
auto const s1 = s{};
auto const f = s1.make_lambda();
auto const g = f; // error here
}
```
As above, the code will fail on both: however clang will report an unavailable copy constructor whereas gcc compiles but raises a multiple definition linker error. With a captured `this`, gcc is happy but clang continues to give the same compilation error. Making the member function `inline` fixes the problem on both.
I'm not certain what the correct behaviour should be here, but either one of clang and gcc is wrong, and even if clang is correct it seems the error messages could be better.
Compiler explorer repro: https://godbolt.org/z/Knfjf3aMe.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0VE2P4zYM_TXKhdjAkTOZ-OBDdoIARbGnFuixoCXa5o4-DElOZvrrC1nOzmy6DQIbhqjH98hHYow8OKJWPH0VT-cNzmn0oX1FG9C5Tef1e_vnSNB7Y_yN3QDKawJDqCMkD9FbWh63ERPMjl2aOfGVgELwASzFiANFIV8AnYYRY7nT0YhX9nMAzX1PgZyiCOxAeTth4Ohdxh-U2orqLKqTOFTrf_mkt8mHBNbr2VB-ifrrGvj5PKYwqwRxPXpeY0DIi5AndoYdCXkS8gI4Jw8WX-lvg7bTKORRyAaUdzGttwDgA2L9BUpzcJDrt2CmkWNBFE_nHP18_kGtAJzvZD4OHsQ9fLK9a30QyS6BRXZQuD6KBCiiFgkQdyDqM8RfcPoU1Zeg3fY_lfi_G8Nyoxf111LVy9r6kQJ9KP2lzOV5ioCdv1K2S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