This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2270. Non-inline functions and explicit instantiation declarations

Section: 13.9.3  [temp.explicit]     Status: NAD     Submitter: Richard Smith     Date: 2016-06-10

Consider:

  template <class F> F foo() { return 1; }
  template <class F> struct S { F foo() { return 1; } };
  extern template int foo<int>();
  extern template struct S<int>;
  int bar() { return foo<int>() + S<int>().foo(); }

An implementation is permitted to instantiate (and thus locally inline) S<int>::foo, but not S<int>, because 13.9.2 [temp.inst] paragraph 10 states:

Except for inline functions, declarations with types deduced from their initializer or return value (9.2.9.7 [dcl.spec.auto]), const variables of literal types, variables of reference types, and class template specializations, explicit instantiation declarations have the effect of suppressing the implicit instantiation of the entity to which they refer.

Additional note (February, 2022):

The paragraph in question was removed by P1815R2 (Translation-unit-local entities) (adopted 2020-02).

EWG 2022-11-11

Any change would require a paper.