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

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

Open
hugoam opened this issue Jan 16, 2022 · 2 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules

Comments

@hugoam
Copy link

hugoam commented Jan 16, 2022

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
@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules and removed new issue labels Jan 16, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 16, 2022

@llvm/issue-subscribers-clang-modules

@urnathan
Copy link
Contributor

urnathan commented Feb 14, 2022

It looks like the mangler's not attaching a discriminating integer to the lambdas?

http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling

<closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _

The number is omitted for the first closure type with a given <lambda-sig> in a given context; it is n-2 for the nth closure type (in [lexical order]) with that same <lambda-sig> and context.

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
Projects
None yet
Development

No branches or pull requests

5 participants