This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-10-26
[Voted into WP at October 2005 meeting.]
13.9.3 [temp.explicit] paragraph 7 says,
The explicit instantiation of a class template specialization implies the instantiation of all of its members not previously explicitly specialized in the translation unit containing the explicit instantiation.
It's not clear whether this “implied” instantiation is implicit or explicit instantiation. It makes a difference in cases like the following:
template <typename T> struct foo { struct bar { }; }; template struct foo<int>; // #1 template struct foo<int>::bar; // #2
If the instantiation of foo<int>::bar implied by #1 is implicit, the explicit instantiation in #2 is well-formed. Otherwise, #2 violates the requirement in 13.9 [temp.spec] that
No program shall explicitly instantiate any template more than once ... for a given set of template-arguments.
It's also unclear whether the implied instantiation applies only to direct members of the class template or to inherited members, as well.
John Spicer: I have always interpreted this as meaning only the members declared in the class, not those inherited from other classes. This is what EDG does, and appears to be what g++, Microsoft and Sun do, too. I also think this is the correct thing for the Standard to require. If I were to derive a class from a class in the standard library, an explicit instantiation of my class should not cause the explicit instantiation of things in the standard library (because the library might provide such explicit instantiations, thus causing my program to run afoul of the "can't instantiate more than once" rule).
Proposed resolution (October, 2004):
Change 13.9.3 [temp.explicit] paragraph 7 as follows:
The explicit instantiation of a class template specializationimplies the instantiation of allalso explicitly instantiates each of its membersnot(not including members inherited from base classes) whose definition is visible at the point of instantiation and that has not been previously explicitly specialized in the translation unit containing the explicit instantiation.