Skip to content

[C++20] [Modules] Exported lambdas is not unique to the TU #186

@ChuanqiXu9

Description

@ChuanqiXu9

Reproducer: https://godbolt.org/z/zG5jKc8ao

export module mod;
export auto f = [] {};
import mod;
int main ()
{
    auto const g = f;
}

And it runs well if we changed the definition of f into export inline auto f = [] {};. Then I realized this may be related to ABI. Itanium C++ ABI 5.1.8 said:

In some contexts, such closure types are unique to the translation unit: This ABI therefore does not specify an encoding for such cases (but an implementation must ensure that any internal encoding does not conflict with this ABI).

In the following contexts, however, the one-definition rule requires closure types in different translation units to "correspond":

  • default arguments appearing in class definitions
  • default member initializers
  • the bodies of inline or templated functions
  • the initializers of inline or templated variables

So in the above example, the two different TU should share the same lambda type and so maybe we need to change the wording here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions