Skip to content

Modules - unexpected error "definition with same mangled name as another definition" with lambdas #53232

Closed
@hugoam

Description

@hugoam

Clang will trigger a compilation error with:

  • (A) a simple module interface with a template function calling a function object passed to it
  • (B) a call to that function from a module passing a lambda twice in the same enclosing scope

This will cause the following compiler error: greetings.cpp:6:6: error: definition with same mangled name '_ZW9greetingsE5greetIZW_0E4testvEUt_EvT_' as another definition

This happens only if the use in (B) is part of a module as well (it can be an implementation unit of the same module, or it can also be part of a second module test which will trigger the error as well).

This seems to be some kind of variation of the following long closed bug: https://bugs.llvm.org/show_bug.cgi?id=33924

greetings.cpp

export module greetings;
 
import <string>;
 
export template <class Func>
void greet(Func f)
{
    return f("Hello, World!");
}

test.cpp

module greetings;
// this would trigger the error as well:
// export module test;
import <iostream>;

int test()
{
    greet([](const std::string& text) { std::cout << text << '\n'; });
    greet([](const std::string& text) { std::cout << text << '\n'; });
    return 1;
}

Compilation commands:

clang++ -Wall -std=c++2a -stdlib=libc++ -fimplicit-modules -fimplicit-module-maps -fmodules --precompile -x c++-module greetings.cpp -o greetings.pcm
clang++ -Wall -std=c++2a -stdlib=libc++ -fimplicit-modules -fimplicit-module-maps -fmodule-file=greetings.pcm -c test.cpp -o test.o

Alternate command if test.cpp is meant to be part of a different module:

clang++ -Wall -std=c++2a -stdlib=libc++ -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=. -c test.cpp -o test.o

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header Modules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions