Hi all, I am studying C++ modules and, especially, trying to understand how implicitly instantiated template specializations are exported.
I encounter an example where GCC and Clang behave differently. For example: /* mod1.cpp */ export module mod1; export { // function template definition template <typename T> T tmpl (T t) { return t; } // explicit instantiation of "char tmpl<char>" template char tmpl (char t); // implicit instantiation of "int tmpl<int>" in exported section int f(int i) { return tmpl(i); } } // implicit instantiation of "double tmpl<double>" in not-exported section double g(double d) { return tmpl(d); } /* main1.cpp */ import mod1; int main() { tmpl('c'); // #1 tmpl(1); // #2 tmpl(1.0); // #3 return 0; } Here, GCC reuses the explicitly instantiated specialization from mod1 at #1. But, it implicitly re-instantiates at #2 and #3. On the other hand, Clang reuses all specializations from module mod1 for each point. So, I read the sections about modules and template instantiations in the working draft of the technical specification [0][1][2]. However, as far as my understanding, there is no explanation about how implicitly instantiated template specializations are exported. According to the comment of gcc/cp/module.c, there seem to be two design choices for exporting implicit specializations: re-instantiating them on-demand (GCC's style) and streaming them (Clang's style) in modules. So my questions are: *Does how implicit specializations are exported depend on compiler implementations?* if not, *Does anyone know the expected behavior based on the technical specification?* Best Regards, Takafumi. [0] <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/n4849.pdf> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/n4849.pdf [1] <http://eel.is/c++draft/>http://eel.is/c++draft/ [2] <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1103r3.pdf> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1103r3.pdf -- Takafumi Kubota Ph.D. student at Keio University http://tk1012.github.io/