-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[C++][Modules] Definition with same mangled name for template arguments of types defined in unnamed namespace in different files #119947
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
Comments
@llvm/issue-subscribers-clang-modules Author: David Stone (davidstone)
Given the following translation units:
export module a;
struct a_inner {
~a_inner() {
}
void f(auto) {
}
};
export template<typename T>
struct a {
a() {
struct local {};
inner.f(local());
}
private:
a_inner inner;
};
namespace {
struct s {
};
} // namespace
void f() {
a<s> x;
} import a;
namespace {
struct s {
};
} // namespace
void g() {
a<s> x;
} clang fails with /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -MD -MT CMakeFiles/foo.dir/b.cpp.o -MF CMakeFiles/foo.dir/b.cpp.o.d @<!-- -->CMakeFiles/foo.dir/b.cpp.o.modmap -o CMakeFiles/foo.dir/b.cpp.o -c /app/b.cpp
In file included from /app/b.cpp:1:
a.cpp:11:8: error: definition with same mangled name '_ZNW1a1aIN12_GLOBAL__N_11sEED2Ev' as another definition
11 | struct a {
| ^
a.cpp:11:8: note: previous definition is here See it live: https://godbolt.org/z/vsdznvsbP |
Oh, name mangling problem. It looks like a hole in the current mangling system. (But I am not familiar with mangling too much) Let me try to send to this to Itanium CXX ABI Group. They are not so active now. And I really to don't want to touch name mangling without the guidance of Itanium CXX ABI . |
After I review it again, I found this is not ABI related. It is forbidden by https://eel.is/c++draft/basic.link#15.4 if the instantiation point is not in a non-inline function body. (So the full explanation in https://eel.is/c++draft/basic.link#14). To fix this, we have to not write instantiations in non-inline function body. |
Given the following translation units:
clang fails with
See it live: https://godbolt.org/z/vsdznvsbP
The text was updated successfully, but these errors were encountered: