<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/129525>129525</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C++20][Modules] Non-exported symbol used by exported one is not isolated from other modules.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
fcojavmc
</td>
</tr>
</table>
<pre>
For my test I use the class/struct 'Impl' defined with the same name in two different modules as a non-exported symbol. That symbol must be only visible inside it's module, not outside. Therefore, one module is isolated from other module.
But, it is not possible to compile the test because there is a name collision.
I also tested it with GCC 15-20250216 and it works as expected.
Tested with latest available compiler/tools:
- Clang 19.1.7 and Clang 20.1.0 (++20250225053057)
- CMake 4.0.0-rc2
- Ninja 1.12.1
CMakeLists.txt
```
cmake_minimum_required(VERSION 4.00)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(PROJECT_NAME "test")
project(${PROJECT_NAME})
set(PROJECT_SRCS "main.cpp")
add_library(core)
target_sources(core
PUBLIC
FILE_SET cxx_modules TYPE CXX_MODULES FILES
mod0.ixx
mod1.ixx
)
add_executable(${PROJECT_NAME} ${PROJECT_SRCS})
target_link_libraries(${PROJECT_NAME} PRIVATE core)
```
main.cpp
```
import mod0;
import mod1;
int main()
{
Mod0 mod0;
mod0.sayHello();
Mod1 mod1;
mod1.sayHello();
return 0;
}
```
mod0.ixx
```
module;
#include <iostream>
#include <memory>
export module mod0;
struct Impl
{
void sayHello()
{
std::cout << "Hello" << std::endl;
}
};
export class Mod0
{
public:
Mod0() : m_pimpl(std::make_unique<Impl>()) {}
void sayHello() const;
private:
std::unique_ptr<Impl> m_pimpl;
};
void Mod0::sayHello() const
{
m_pimpl->sayHello();
}
```
mod1.ixx
```
module;
#include <iostream>
#include <memory>
export module mod1;
struct Impl
{
void sayHello()
{
std::cout << "Hello" << std::endl;
}
};
export class Mod1
{
public:
Mod1() : m_pimpl(std::make_unique<Impl>()) {}
void sayHello() const;
private:
std::unique_ptr<Impl> m_pimpl;
};
void Mod1::sayHello() const
{
m_pimpl->sayHello();
}
```
Error:
```
[4/5] Building CXX object CMakeFiles/test.dir/main.cpp.o
FAILED: CMakeFiles/test.dir/main.cpp.o
/usr/bin/clang++ -stdlib=libc++ -O3 -DNDEBUG -std=gnu++23 -MD -MT CMakeFiles/test.dir/main.cpp.o -MF CMakeFiles/test.dir/main.cpp.o.d @CMakeFiles/test.dir/main.cpp.o.modmap -o CMakeFiles/test.dir/main.cpp.o -c /src/main.cpp
In file included from /src/main.cpp:1:
/src/mod0.ixx:7:8: error: declaration 'Impl' attached to named module 'mod0' cannot be attached to other modules
7 | struct Impl
| ^
/src/mod1.ixx:7:8: note: also found
7 | struct Impl
| ^
1 error generated.
ninja: build stopped: subcommand failed.
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEV09z27oR_zTQZUccEhRN6aADJVKvai07tZ03rycNSEASEhDgA0DH-vYdgJBMJ_Y0nTatJhNL-38Xi90fiDH8KBlbomyFsnJCentSenlo1Bfy3DaTWtHzcqM0tGewzFjYQm8Y2BODRhBjEN4Yq_vGAsL5tu0EwjlQduCSUfjG7cmLGtIykO4_LsF-U0D54cA0kxZaRXvBDBADBKSSU_bSKW0ZBXNuayUieDoRG35A2xsLNQMlxRmeueG1cDYNpwy4RTg3wSDCa5DKguqtYzorTLOD0p6jJAtywA1wowRxHg9ataDsienAjVBcoLhY9dZpceukndVOmcG1VdCotuNiKImvUM0aEmqkvX0ypN4oIbjhSgarWyDCKK_DqDPuy_Xbeg1JNsUxzmKc3ACRA0_pr75I7KVjjWU0GHkatL2qS8JYIM-EC-KiC6FphDdWKWFQWgxaU1gLIo-QLKIkyr2PgYDjKIliQHiO8Arh1RAGzuIsjbMc4cWgvCNfGcyiOIqnusGedsflFwJJlOAoGZyguPCCt9xYE9kX62g3cfgXF01LvrJ9yyV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