<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/102360>102360</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C++20][Modules] Variable template in instantiation chain attached to wrong module
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
davidstone
</td>
</tr>
</table>
<pre>
Given the following translation units:
```c++
export module a;
template<typename>
constexpr auto impl = true;
export template<typename T>
void a() {
}
export template<typename T> requires impl<T>
void a() {
}
```
```c++
export module b;
import a;
static void b() {
a<void>();
}
```
```c++
export module c;
import a;
static void c() {
a<void>();
}
```
```c++
import a;
import b;
import c;
static void d() {
a<void>();
}
```
clang incorrectly errors with
```console
In file included from /app/d.cpp:1:
a.cpp:4:16: error: declaration 'impl<void>' attached to named module 'b' can't be attached to other modules
4 | constexpr auto impl = true;
| ^
a.cpp:4:16: note: also found
1 error generated.
```
See it live: https://godbolt.org/z/fKEvse3PK
This occurs even if `impl` is declared `static`, but does not seem to occur if `impl` is declared in the unnamed namespace. That workaround does not work for me, because this was reduced from a bug where clang complained about a variable template specialization of a variable template exported in a different module.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vd9v4zYM_muUF-ICWU7s5MEPbdIMw2HAgBV7pyU61iZLnn4k1_vrB9lJ26Xd4YrtAsMxSOrTx08khSHooyVq2PqerfcLTLF3vlF40ipEZ2nROvXU_KRPZCH2BJ0zxp21PUL0aIPBqJ2FZHUMrLxjfM_49V3x-ZFM3OdnstKX0fkIg1PJECAr71-viTSMBiOxchefRrI4ECsfZp90NkT6MnrAFB3oYTTAyj1En-gG5rLJO2jw-Ix3cloBMrFhYgusvgLU-w8ggae_kvYUJjqs3H0__FWdj0rW3uSqh8l7q2SIGLWEiUX7hgXfIit32Zn5Tt6X9f-Zovw4RfnDKb4hcTG0t4Zb9q9pqv-RpjRoj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