<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/108831>108831</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-19, rc4] [cxx-modules] error: declaration attached to named module can't be attached to 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>
Silverlan
</td>
</tr>
</table>
<pre>
Repository with reduced code for reproduction: https://github.com/Silverlan/test_cxx_modules
I have a simple cxx-module library consisting of two module fragments, `a` and `b`.
`a.cppm`:
```cpp
module;
export module test_module.a;
export namespace test_module {
class A {
public:
#ifdef DEFINE_IN_CLASS
class B* GetB() { return nullptr; }
#else
class B* GetB();
#endif
};
};
```
`b.cppm`:
```cpp
module;
export module test_module.b;
export namespace test_module {
class B {
public:
};
};
```
The method in class `A` uses class `B` by forward declaration. The method is defined in a separate cpp-file, `a.cpp` (unless `DEFINE_IN_CLASS` is defined).
`a.cpp`:
```cpp
module;
module test_module.a;
import test_module.b;
#ifndef DEFINE_IN_CLASS
class test_module::B* test_module::A::GetB() { return nullptr; }
#endif
```
There are four test cases:
1) clang-18, `DEFINE_IN_CLASS` defined: Build is successful.
2) clang-18, `DEFINE_IN_CLASS` *not* defined: Build is successful.
3) clang-19, `DEFINE_IN_CLASS` defined: Build is successful.
3) clang-19, `DEFINE_IN_CLASS` *not* defined: Build fails with the following error:
```
FAILED: CMakeFiles/test_lib.dir/Debug/src/a.cpp.o
/home/runner/work/test_cxx_modules/test_cxx_modules/LLVM-19.1.0-rc4-Linux-X64/bin/clang++ -DCMAKE_INTDIR=\"Debug\" -g -std=gnu++20 -MD -MT CMakeFiles/test_lib.dir/Debug/src/a.cpp.o -MF CMakeFiles/test_lib.dir/Debug/src/a.cpp.o.d @CMakeFiles/test_lib.dir/Debug/src/a.cpp.o.modmap -o CMakeFiles/test_lib.dir/Debug/src/a.cpp.o -c /home/runner/work/test_cxx_modules/test_cxx_modules/src/a.cpp
In file included from /home/runner/work/test_cxx_modules/test_cxx_modules/src/a.cpp:9:
/home/runner/work/test_cxx_modules/test_cxx_modules/src/b.cppm:6:8: error: declaration 'B' attached to named module 'test_module.b' can't be attached to other modules
6 | class B {
| ^
/home/runner/work/test_cxx_modules/test_cxx_modules/src/a.cppm:11:9: note: also found
11 | class B* GetB();
| ^
1 error generated.
ninja: build stopped: subcommand failed.
Error: Process completed with exit code 1.
```
Steps to reproduce:
1) Fork https://github.com/Silverlan/test_cxx_modules
2) Run the action/workflow `Clang Build Error`
3) You can see each test case in the workflow log:
![firefox_ZQY00qO7Dm](https://github.com/user-attachments/assets/37a4908e-0399-4670-bf61-64f4310534c5)
Alternatively you can also reproduce it locally by cloning the repository and building it with clang-19 (rc4). `DEFINE_IN_CLASS` can be enabled/disabled with CMake:
```
git clone https://github.com/Silverlan/test_cxx_modules
cd test_cxx_modules
mkdir -p build
cd build
cmake -DDEFINE_IN_CLASS=OFF -DCMAKE_C_COMPILER=../LLVM-19.1.0-rc4-Linux-X64/bin/clang -DCMAKE_CXX_COMPILER=../LLVM-19.1.0-rc4-Linux-X64/bin/clang++ -G "Ninja Multi-Config" -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
```
(Replace the paths to clang-19 compiler. I've also only tested it with ninja.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysWF1zmzwW_jXyzRkYEBjsC1_YJryT2aTtpt2ddm8yQhxsvRESK4l8_PsdgT_bJJsm7XRiWRw9Ot_PwcxasVGICzJdkWkxYb3barP4KuQ9GsnUpNL10-IGO22F0-YJHoTbgsG651gD1zVCow0Y7Iyue-6EViRZwta5zpJkSWhJaLkRbttXIdctoeUBmtDSoXW3_PHxttV1L9GSqCDRcvx7CVt2j8DAiraTCPzxMRjFQIrKMPMEXCsrrBNqA7oB96BhJ9AYtmlROUvoGkgWMZJFwFTt1xXJonB3URaxkHddS7LIK7vfHP_zrht3RlCSrE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