Created on 2008-12-29.00:00:00 last changed 33 months ago
[Voted into WP at March, 2010 meeting.]
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
onlyan 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,otherexplicit instantiation declarations have the effect of suppressing the implicit instantiation of the entity to which they refer...
Suggested resolution:
Change 13.9.3 [temp.explicit] paragraph 7 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.
Change 13.9.3 [temp.explicit] paragraph 9 as follows:
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...
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:23 | admin | set | messages: + msg6701 |
2010-03-29 00:00:00 | admin | set | messages: + msg2738 |
2010-03-29 00:00:00 | admin | set | status: ready -> cd2 |
2009-11-08 00:00:00 | admin | set | messages: + msg2379 |
2009-11-08 00:00:00 | admin | set | status: open -> ready |
2008-12-29 00:00:00 | admin | create |