llvm / llvm/llvm-project

definition with same mangled name when using c++20 modules, templates and libstdc++

Open
#171,548 10 comments 0 reactions 1 assignee Claimed by @ChuanqiXu9 View on GitHub
accepts-invalid clang:modules
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

`main.cpp`
```cxx
import pollcoro;
import helper;

int main() {
pollcoro::block_on(helper::async(0));
}

```

This fails to compile with the following:

```sh
/nix/store/90lsdrdffwgf3kjd4sdxjchchg44cr02-clang-wrapper-20.1.8/bin/clang++ -O3 -O3 -DNDEBUG -std=c++20 -fvisibility=hidden -fvisibility-inlines-hidden -MD -MT CMakeFiles/thing.dir/src/main.cpp.o -MF CMakeFiles/thing.dir/src/main.cpp.o.d @CMakeFiles/thing.dir/src/main.cpp.o.modmap -o CMakeFiles/thing.dir/src/main.cpp.o -c /home/troy/github/paravision/tmp/src/main.cpp
In module 'pollcoro' imported from /home/troy/github/paravision/tmp/src/main.cpp:8:
In module 'pollcoro:mutex' imported from /home/troy/github/paravision/tmp/build/_deps/pollcoro-src/src/pollcoro.cppm:46:
/nix/store/y28c83zz73yr4vwz1fsl4nsrn6yz5fj0-gcc-14.3.0/include/c++/14.3.0/x86_64-unknown-linux-gnu/bits/gthr-default.h:313:1: error: definition with same mangled name '_ZL18__gthread_active_pv' as another definition
313 | __gthread_active_p (void)
| ^
/nix/store/y28c83zz73yr4vwz1fsl4nsrn6yz5fj0-gcc-14.3.0/include/c++/14.3.0/x86_64-unknown-linux-gnu/bits/gthr-default.h:313:1: note: previous definition is here
313 | __gthread_active_p (void)
| ^
1 error generated.
ninja: build stopped: subcommand failed.
error: Recipe `build` failed on line 2 with exit code 1
```

`helper.cppm`
```cxx
module;

#include

export module helper;

import pollcoro;

export namespace helper {
template
auto async(T value) {
auto [awaitable, setter] = pollcoro::single_event();

setter.set(std::move(value));

return std::move(awaitable);
}

} // helper
```

`pollcoro` is https://github.com/troyKomodo/pollcoro

The following 2 fix the error:

- adding `#include ` to `main.cpp`
- removing the template on `helper` in `helper.cppm`

Reproducible repo: https://github.com/TroyKomodo/cxx-compiler-bug

Possibly related:
https://github.com/llvm/llvm-project/issues/137533

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.