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


1163. extern template prevents inlining functions not marked inline

Section: 13.9.3  [temp.explicit]     Status: NAD     Submitter: US     Date: 2010-08-03

N3092 comment US 76

According to 13.9.3 [temp.explicit] paragraph 9,

Except for inline functions and class template specializations, explicit instantiation declarations have the effect of suppressing the implicit instantiation of the entity to which they refer.

This means that an implementation cannot do inline expansion of an extern template function or member function, because that would require its instantiation. As a result, adding an explicit instantiation declaration can affect performance, even though the user only intended to suppress out-of-line copies of functions.

Rationale (August, 2010):

If implementations are allowed to do speculative instantiation for the purpose of inlining, there could be silent changes of meaning depending on whether the instantiation is done or not.