Skip to content

[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

Open
davidstone opened this issue Dec 14, 2024 · 3 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules

Comments

@davidstone
Copy link
Contributor

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

@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules and removed new issue labels Dec 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 14, 2024

@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&lt;typename T&gt;
struct a {
	a() {
		struct local {};
		inner.f(local());
	}
private:
	a_inner inner;
};


namespace {

struct s {
};

} // namespace

void f() {
	a&lt;s&gt; x;
}
import a;

namespace {

struct s {
};

} // namespace

void g() {
	a&lt;s&gt; 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

@ChuanqiXu9
Copy link
Member

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 .

@ChuanqiXu9
Copy link
Member

ChuanqiXu9 commented Jan 15, 2025

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.

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

4 participants