Re: GCC 10.2: undefined reference to vtable: missing its key function

2021-06-08 Thread Jonathan Wakely via Gcc
(This should have been on the gcc-help list.)

> I may be remembering wrong, but -- doesn't dynamic_cast look for a vtable?

It uses a vtable if one is present, it can't cause one to be
introduced, so ...

>So if you do a dynamic cast mentioning that class you'd get such a reference.

No.

> Or is that an error when applied to a non-polymorphic class?

You can use dynamic_cast to upcast (i.e. from derived to base) for
non-polymorphic class types. It is an error to downcast (from base to
derived) for a non-polymorphic class type.




Re: GCC 10.2: undefined reference to vtable: missing its key function

2021-06-07 Thread Paul Koning via Gcc



> On Jun 6, 2021, at 5:41 PM, Paul Smith  wrote:
> 
> I have a class which is NOT, as far as I can see, polymorphic.
> 
> It doesn't inherit from any other class and none of its methods are
> declared virtual.  The class implementation and all its callers all
> compile just fine.
> 
> Is there some other way that a class can be thought to be virtual,
> stealthily (say by its usage in some other class or something)?

I may be remembering wrong, but -- doesn't dynamic_cast look for a vtable?  So 
if you do a dynamic cast mentioning that class you'd get such a reference.  Or 
is that an error when applied to a non-polymorphic class?

paul




Re: GCC 10.2: undefined reference to vtable: missing its key function

2021-06-07 Thread Paul Smith
On Sun, 2021-06-06 at 17:41 -0400, Paul Smith wrote:
> How can I figure out why the compiler decides, while compiling
> foo.cxx, that MyClass is virtual and needs a vtable when as far as I
> can tell it's not (if I use nm on MyClass.o I see no hints of vtable
> etc.)

Err... I think this might have been a problem caused by ccache :(.

Not sure how but cannot reproduce after I deleted my cache.  Sigh.



GCC 10.2: undefined reference to vtable: missing its key function

2021-06-06 Thread Paul Smith
I have a class which is NOT, as far as I can see, polymorphic.

It doesn't inherit from any other class and none of its methods are
declared virtual.  The class implementation and all its callers all
compile just fine.

Is there some other way that a class can be thought to be virtual,
stealthily (say by its usage in some other class or something)?

The problem is that when I link this class I get a linker error from
gold:

  MyClass.h:25: error: undefined reference to 'vtable for MyClass'
ld: the vtable symbol may be undefined because the class is missing its
key function

Line 25 is the first method in the class (a constructor).

Sure enough if I use nm -C on the other object files I'm linking, I see
things like this:

   foo.o:  U vtable for MyClass

How can I figure out why the compiler decides, while compiling foo.cxx,
that MyClass is virtual and needs a vtable when as far as I can tell
it's not (if I use nm on MyClass.o I see no hints of vtable etc.)

This is with GCC 10.2 / binutils 2.35.1 (x86_64)