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: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Matt Austern <austern at apple dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: 10 Oct 2002 23:22:32 +0200
- Subject: Re: When to emit the vtable for a class template
- Organization: Integrable Solutions
- References: <E2FAA71C-DC94-11D6-80E4-00039390D9E0@apple.com>
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".
Consider
struct A;
A* foo(X* p) { return p + 1; }
That is a valid construct that does not need completeness of type A and
the situation is not different from the X<int> case.
| However, compiling this
| with -S and looking at the assembly code, I'm not seeing
| X<int>'s vtable.
I fear the vtable for X<int> does not need to be emitted.
| So, my question stands: under what circumstances does the
| compiler emit a vtable for a polymorphic class template?
I'm however unable to give an informed answer to this question.
| Is
| the answer the same as what the ABI specification says it
| should be?
I would expect so.
-- Gaby