Issue 96428
Summary Strange behaviour with lambdas returned from module exported member function
Labels new issue
Assignees
Reporter kamrann
    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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to