C++11 §2.2 Phases of translation, 8th phrase. Translated translation units and instantiation units are combined as follows. What's the exact meaning of "instantiation unit"?
Instantiation units are template instantiations (implicit and explicit).
For example, for this template :
template < typename T >
struct A
{
};
this :
template class A<int>;
with addition of the above template declaration and definition, is one instantiation unit.
The meaning hasn't changed since the C++98 standard, since this was the original C++ compilation model - instantiation units are separate files where template instantiations encountered by the compiler in a TU are stored, so that each template instantiation is compiled only once per program.
To quote IBM compiler documentation on their -qtemplateregistry
option,
When a compilation unit instantiates a new instance for the first time, the compiler creates this instance and keeps the record in a registry file. [...] When another compilation unit references the same instantiation and uses the same registry file as in the previous compilation unit, this instance will not be instantiated again. Thus, only one copy is generated for the entire program.
Oracle has a more extensive documentation on the C++ template compilation model.
GCC doesn't have an automatic repository, but the docs seem to imply that similar results can be obtained by compiling with -frepo
and running collect2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With