This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: When to emit the vtable for a class template


On Thursday, October 10, 2002, at 02:22 PM, Gabriel Dos Reis wrote:

Matt Austern <austern@apple.com> writes:

[...]

| Consider the following translation unit:
|
|      template<class T> struct X {
|        virtual void foo();
|        virtual ~X();
|      };
|
|      template <class T> void X<T>::foo() { }
|
|
|      X<int>* xyzzy(X<int>* p) {
|        return p + 1;
|      }
|
| Clearly X<int> must be instantiated.

Hmm, if "instantiated" is used as the C++ standard uses it, then I'm
not clear why X<int> ought to be instantiated.  AFAIK, only the
template-id 'X<int>' needs to be "instantiated".
5.7, paragraph 1: "For addition ... one operand shall be a pointer to
a completely defined object type and the other shall have integral
or enumeration type".  (Intuitively, X<int> needs to be complete for
pointer arithmetic to work because we need to know X<int>'s size.)

Since X<int> has to be a complete type, it follows from 14.7.1,
paragraphs 1 and 4, that this is an implicit instantiation of X<int>.

My (possibly incorrect) reading of the ABI specification is that an
implicit instantiation of a polymorphic class template results in
having its vtable emitted.

			--Matt


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]