Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour with lambdas returned from module exported member function #96428

Closed
kamrann opened this issue Jun 23, 2024 · 2 comments
Closed
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules duplicate Resolved as duplicate

Comments

@kamrann
Copy link

kamrann commented Jun 23, 2024

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.

@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules and removed new issue labels Jun 23, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2024

@llvm/issue-subscribers-clang-modules

Author: Cameron Angus (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.
</details>

@ChuanqiXu9 ChuanqiXu9 self-assigned this Jun 25, 2024
@ChuanqiXu9
Copy link
Member

This looks duplicated with #59513

@ChuanqiXu9 ChuanqiXu9 reopened this Jun 25, 2024
@ChuanqiXu9 ChuanqiXu9 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
@ChuanqiXu9 ChuanqiXu9 added the duplicate Resolved as duplicate label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants