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


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


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