Title
Instantiation of members of an explicitly-instantiated class template
Status
cd1
Section
13.9.3 [temp.explicit]
Submitter
Matt Austern

Created on 2004-05-11.00:00:00 last changed 162 months ago

Messages

Date: 2005-10-15.00:00:00

[Voted into WP at October 2005 meeting.]

Date: 2004-10-15.00:00:00

Proposed resolution (October, 2004):

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

The explicit instantiation of a class template specialization implies the instantiation of all also explicitly instantiates each of its members not (not including members inherited from base classes) whose definition is visible at the point of instantiation and that has not been previously explicitly specialized in the translation unit containing the explicit instantiation.
Date: 2004-05-11.00:00:00

13.9.3 [temp.explicit] paragraph 7 says,

The explicit instantiation of a class template specialization implies the instantiation of all of its members not previously explicitly specialized in the translation unit containing the explicit instantiation.

It's not clear whether this “implied” instantiation is implicit or explicit instantiation. It makes a difference in cases like the following:

    template <typename T> struct foo {
        struct bar { };
    };

    template struct foo<int>;         // #1

    template struct foo<int>::bar;    // #2

If the instantiation of foo<int>::bar implied by #1 is implicit, the explicit instantiation in #2 is well-formed. Otherwise, #2 violates the requirement in 13.9 [temp.spec] that

No program shall explicitly instantiate any template more than once ... for a given set of template-arguments.

It's also unclear whether the implied instantiation applies only to direct members of the class template or to inherited members, as well.

John Spicer: I have always interpreted this as meaning only the members declared in the class, not those inherited from other classes. This is what EDG does, and appears to be what g++, Microsoft and Sun do, too. I also think this is the correct thing for the Standard to require. If I were to derive a class from a class in the standard library, an explicit instantiation of my class should not cause the explicit instantiation of things in the standard library (because the library might provide such explicit instantiations, thus causing my program to run afoul of the "can't instantiate more than once" rule).

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2006-04-22 00:00:00adminsetstatus: dr -> wp
2005-10-22 00:00:00adminsetmessages: + msg1288
2005-10-22 00:00:00adminsetstatus: ready -> dr
2005-05-01 00:00:00adminsetstatus: review -> ready
2004-11-07 00:00:00adminsetmessages: + msg1072
2004-11-07 00:00:00adminsetstatus: open -> review
2004-05-11 00:00:00admincreate