Skip to content

[Clang][Module] Miss definition of inline function in implementation partition units #101348

@24bit-xjkp

Description

@24bit-xjkp

Information

clang version 20.0.0git (https://github.com/llvm/llvm-project.git 73c72f2)
Target: x86_64-unknown-windows-gnu
Thread model: posix
InstalledDir: D:/Tools/clang/bin
OS: Windows11 24H2

Here is my code:

// a.cpp
import B;
int main()
{
    g<void>();
}
// b.cppm
export module B;
import :C;
export template <typename T> inline void g() noexcept
{
    return f<T>();
}
// c.cppm
module B:C;
template<typename> inline void f() noexcept {}

I can compile these code with gcc and msvc, but when I compile with clang:

mkdir build
clang++ -std=c++26 c.cppm --precompile -o build/c.pcm
clang++ -std=c++26 b.cppm "-fmodule-file=B:C=build/c.pcm" --precompile -o build/b.pcm
clang++ -std=c++26 a.cpp "-fmodule-file=B=build/b.pcm" "-fmodule-file=B:C=build/c.pcm"

Then I receive errors below:

In module 'B' imported from a.cpp:1:
C:/Users/2283/Desktop/test/c.cppm:4:13: warning: inline function 'f<void>' is not defined [-Wundefined-inline]
    4 | inline void f() noexcept
      |             ^
C:/Users/2283/Desktop/test/b.cppm:7:12: note: used here
    7 |     return f<T>();
      |            ^
1 warning generated.
ld.lld: error: undefined symbol: void f@B<void>()
>>> referenced by C:/Users/2283/AppData/Local/Temp/a-7d0622.o:(void g@B<void>())
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Clang doesn't generate code correctly for the inline function f<void> therefore lld can't find the symbol f@B<void>() while linking objects.

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header ModulesinvalidResolved as invalid, i.e. not a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions