On 25.02.2017 14:46, Shiyao Ma wrote:
> My question has nothing to do with `explicit instantiation'
>
> I was saying `explicit specialization', not `explicit instantiation'.
>
OK, I see.
A full specialization of a template is technically very similar to an
ordinary non-template definition, so I guess in practice it might indeed
have the same effect as an explicit instantiation. However, from reading
the standard I get the feeling this is not guaranteed.
I think the most relevant point is 14/6:
"A function template, member function of a class template, variable
template, or static data member of a class template shall be defined in
every translation unit in which it is implicitly instantiated (14.7.1)
unless the corresponding specialization is explicitly instantiated
(14.7.2) in some translation unit; no diagnostic is required."
Note that this "explicit specialization" is not mentioned here. I
believe that if it was meant to have the same effect, it would have been
included here.
So my take at the moment is that in order to be standard-compliant one
needs to also add explicit instantiation after the explicit
specialization when the latter is not visible in all relevant TU-s; if
it accidentally works without explicit specialization then it is thanks
to the "no diagnostic required" loophole above.