Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

does the language guarantee `explicit specialization' will generate the code ?

16 views
Skip to first unread message

Shiyao Ma

unread,
Feb 25, 2017, 2:24:19 AM2/25/17
to
Hi,

Does the standard say, if a template is explicitly specialized, the compiler will emit the machine code?


If so, what part?

http://eel.is/c++draft/temp.spec doesn't seem to force the compiler to generate the code.

I'd afraid this might result a link error.


Regards.

Paavo Helde

unread,
Feb 25, 2017, 3:49:54 AM2/25/17
to
Explicit specialization and explicit instantiation are different things.
Only the latter forces instantiation (aka "code generation" in your terms).


Shiyao Ma

unread,
Feb 25, 2017, 7:46:30 AM2/25/17
to
My question has nothing to do with `explicit instantiation'

I was saying `explicit specialization', not `explicit instantiation'.



Paavo Helde

unread,
Feb 25, 2017, 10:16:35 AM2/25/17
to
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.


Paavo Helde

unread,
Feb 25, 2017, 10:20:21 AM2/25/17
to
On 25.02.2017 17:16, Paavo Helde wrote:
> accidentally works without explicit specialization

s/specialization/instantiation/

my head starts aching ... ;-)

0 new messages