<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125521>125521</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang++] Implicit template instantiations in modules cause errors in other modules
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
BernardoGomesNegri
</td>
</tr>
</table>
<pre>
If module A instantiates a template Class\<T\>, any module that imports module A and also tries to instantiate Class\<T\> (with the same T) will get an error:
```
/home/modBug/reproducer/src/hello.h:8:38: error: declaration 'get' attached to named module 'Mod2' can't be attached to other modules
8 | template <typename V> friend int get() noexcept;
| ^
/home/modBug/reproducer/src/hello.h:3:27: note: also found
3 | template <typename V> int get() noexcept {return 0;};
| ^
```
See [this reproducer](https://github.com/user-attachments/files/18644458/reproducer.zip) or https://godbolt.org/z/d7YW7TM4a where instantiating List\<int\> in Mod2 causes any module that also imports Mod2 to fail to instantiate List\<int\>.
I think this is a bug because the global module fragment is not supposed to be exported.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVEFv4zYT_TXjyyCGNLIi-aCD7aw-BPi2lwYteqTEscSWIgVytNnsry8oOxsnSHsoIZiAMXx88-Y9qhjN4JgbKI9QPmzUIqMPzZGDU0H7__mJ4y88BLPpvH5pHs84eb1YxgMaF0U5MUo4okLhabZKGE9WxQjlCYrT07p9ATqhci-vR2VUgmaafZD4BqecRmWjRwmGI4q_veATUASqn42MKCNjVBPjE9Aen421OLCgcsgh-ADFAbID3GfXLzsAtaOfGKidvD4uA1AbeA5eLz0HoDaGPpWwtX47QnGooTgU6ecnIGrurQpKjHcIVA0sQBUqEdWPrBN5pybWr90BVV-9plTTKwdUCXb8rtzLyOFaHiE7YI1QnTCtn8JCcZKXmRMy_pYUOAfDTqNxgiuDOgngPH_veRYojglnXQkKyi__ofcCigNVqWXnhdO-zujsF6ev8MUK_88sP6eHUB0DyxIcZolq9XAl_Nr25-vaxc00f2VGKI8ymog3rZQPQPUoMsdkAGqB2sHIuHTb3k9A7RI53F0mMLGTCNSeTdKe2ry-3-12Zf1Om-0PMyf-PuAHVK87b2XrQxLzB1Crqz9-r56-7hQ-jxz4xsfGDfh_E-ViZOPkamXjMPkDe7XEFKYPWVklfw3MWigez8rYjyn5BHsL2eERZTTuL1w1Mims3TJgx-t1a34G6ztlXy89BzUkUVKt84JxmWcfL0btGPl7YsJ6u9FNoffFXm24yauiLvdVdV9txqbKz0XJpb4nUkVR1QXpcn_WO-op3-t73piGMiozyoq83O2p2u5rIqpyzss8U1nZwy7jSRm7tfbblLTdmBgXbnIqS8o3VnVs4_poEfVWuQGI0vsVmnTgrluGCLvMmijxDUKM2PWlu544pq98wMdptqY38mbim5F5F9N8rtG8jOjyEKz_vwvuZgm2-RfTJSbX7W4O_k_uBahdO1uNd2nuW0N_BwAA__8btMb5">