Skip to content

Lambdas cannot be used inside C++20 modules because they share the “definition with same mangled name” #52857

@ruoka

Description

@ruoka

How to reproduce:

// module.cpp 
export module test;
export namespace test
{
    auto foo = [] {return 1;};
    auto bar = [] {return 'a';};
}

// main.cpp 
import test;
int main()
{
    test::foo();
    test::bar();
}

$ clang++ -std=c++20 -fprebuilt-module-path=. -Xclang -emit-module-interface -c module.cpp -o test.pcm
$ clang++ -std=c++20 -fprebuilt-module-path=. main.cpp test.pcm -o main

In file included from main.cpp:1:
./module.cpp:6:16: error: definition with same mangled name '_ZW4testENK4testUt_clEv' as another definition
auto bar = [] {return 'a';};
^
./module.cpp:5:16: note: previous definition is here
auto foo = [] {return 1;};
^

Metadata

Metadata

Assignees

Labels

c++20clang:modulesC++20 modules and Clang Header Modules

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions