Title
Explicit instantiation declaration and “preceding initialization”
Status
nad
Section
13.9.3 [temp.explicit]
Submitter
Hubert Tong

Created on 2015-07-22.00:00:00 last changed 103 months ago

Messages

Date: 2015-10-15.00:00:00

Rationale (October, 2015):

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

Date: 2022-11-20.07:54:16

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 (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. [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?

History
Date User Action Args
2015-11-10 00:00:00adminsetmessages: + msg5985
2015-07-22 00:00:00admincreate