This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: When to emit the vtable for a class template
- From: Matt Austern <austern at apple dot com>
- To: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 10 Oct 2002 14:35:40 -0700
- Subject: 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