This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See for the official list.


2161. Explicit instantiation declaration and “preceding initialization”

Section: 13.9.3  [temp.explicit]     Status: NAD     Submitter: Hubert Tong     Date: 2015-07-22

Consider the following example:

  template <typename T> extern const decltype(sizeof 0) Sz = sizeof(T);
  extern template const decltype(sizeof 0) Sz<int>;

  constexpr decltype(sizeof 0) x = Sz<int>;

C++14 allows this, exempting “const variables of literal type" from the effects of an explicit instantiation declaration:

Except for inline functions, declarations with types deduced from their initializer or return value ( []), 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. [Note: The intent is that an inline function that is the subject of an explicit instantiation declaration will still be implicitly instantiated when odr-used (6.3 [basic.def.odr]) so that the body can be considered for inlining, but that no out-of-line copy of the inline function would be generated in the translation unit. —end note]

Should there be a DR against C++11 for the similar case of a static data member of a class template?

Rationale (October, 2015):

CWG agreed that this was a defect in C++11, but it is addressed in C++14.