[cxx-abi-dev] Key functions and templates

Lawrence Crowl crowl at google.com
Mon Feb 22 23:52:53 UTC 2010


On 2/22/10, Mark Mitchell <mark at codesourcery.com> wrote:
> Lawrence Crowl wrote:
> >  A translation unit declares an "extern template" specialization
> >  of G_key_defined<int>::f().  The compiler infers that the virtual
> >  table need not be generated even though the translation unit
> >  otherwise instantiates G_key_defined<int>.  The specialization of
> >  f() is not subsequently used, and so the vtable will fail to exist.
>
> Is this a valid program?

Hm.  No.  If a class is used, its virtual functions must be defined
even when not used, unlike non-virtual methods.

> If the vtable was created at the point it is
> referenced, it would reference the virtual function "f", not otherwise
> used, by hypothesis.  Are we allowed to instantiate the function at this
> point?  (This is not a rhetorical question; I don't recall what the
> standard says about the point of instantiation in this case.)

I don't think the standard is clear on that.  It says that "extern
template" is an explicit instantiation declaration, but doesn't
seem to say whether or not one is required to have an explicit
instantiation definition to go with it.

> In any cases, Alasdair is saying that G++ generates too many
> vtables, not too few; this seems potentially non-optimal, but I
> don't see how it breaks anything.

Right, but I think the real question is "can we eliminate the
redundancy without breaking the ABI?"

-- 
Lawrence Crowl



More information about the cxx-abi-dev mailing list