Title
Explicit instantiation declarations of class template specializations
Status
cd2
Section
13.9.3 [temp.explicit]
Submitter
Jason Merrill

Created on 2008-12-29.00:00:00 last changed 26 months ago

Messages

Date: 2010-03-15.00:00:00

[Voted into WP at March, 2010 meeting.]

Date: 2009-10-15.00:00:00

Proposed resolution (October, 2009):

Change 13.9.3 [temp.explicit] paragraphs 7-9 as follows:

An explicit instantiation that names a class template specialization is also an explicit instantion of the same kind (declaration or definition) of each of its members (not including members inherited from base classes) that has not been previously explicitly specialized in the translation unit containing the explicit instantiation, except as described below. [Note: In addition, it will typically be an explicit instantiation of certain implementation-dependent data about the class. —end note]

An explicit instantiation definition that names a class template specialization explicitly instantiates the class template specialization and is only an explicit instantiation definition of only those members whose definition is visible at the point of instantiation.

An explicit instantiation declaration that names a class template specialization has no effect on the class template specialization itself (except for perhaps resulting in its implicit instantiation). Except for inline functions and class template specializations, other explicit instantiation declarations have the effect of suppressing the implicit instantiation of the entity to which they refer...

Date: 2022-02-18.07:47:23

Suggested resolution:

  1. Change 13.9.3 [temp.explicit] paragraph 7 as follows:

  2. An explicit instantiation that names a class template specialization is also an explicit instantion of the same kind (declaration or definition) of each of its members (not including members inherited from base classes) that has not been previously explicitly specialized in the translation unit containing the explicit instantiation, except as described below.
  3. Change 13.9.3 [temp.explicit] paragraph 9 as follows:

  4. An explicit instantiation declaration that names a class template specialization has no effect on the class template specialization itself (except for perhaps resulting in its implicit instantiation). Except for inline functions and class template specializations, other explicit instantiation declarations have the effect of suppressing the implicit instantiation of the entity to which they refer...
Date: 2022-02-18.07:47:23

Consider this example:

    template <class T> struct A {
       virtual void f() {}
    };

    extern template struct A<int>;

    int main() {
       A<int> a;
       a.f();
    }

The intent is that the explicit instantiation declaration will suppress any compiler-generated machinery such as a virtual function table or typeinfo data in this translation unit, and that because of 13.9.3 [temp.explicit] paragraph 10,

An entity that is the subject of an explicit instantiation declaration and that is also used in the translation unit shall be the subject of an explicit instantiation definition somewhere in the program; otherwise the program is ill-formed, no diagnostic required.

the use of A<int> in declaring a requires an explicit instantiation definition in another translation unit that will provide the requisite compiler-generated data.

The existing wording of 13.9.3 [temp.explicit] does not express this intent clearly enough, however.

History
Date User Action Args
2022-02-18 07:47:23adminsetmessages: + msg6701
2010-03-29 00:00:00adminsetmessages: + msg2738
2010-03-29 00:00:00adminsetstatus: ready -> cd2
2009-11-08 00:00:00adminsetmessages: + msg2379
2009-11-08 00:00:00adminsetstatus: open -> ready
2008-12-29 00:00:00admincreate