[MAJOR BUG] g++ 2.95.x generates invalid code for KDE 3.3.0

Guillaume Laurent glaurent at telegraph-road.org
Mon Sep 20 07:59:13 BST 2004

On Monday 20 September 2004 01:46, Thiago Macieira wrote:
> Guillaume Laurent wrote:
> >> The problem in this case is that a virtual function is called
> >> *indirectly* from inside the constructor: the constructor calls a
> >> function which in turn calls the virtual function.
> >
> >It's the exact same problem, as long as you're in a ctor, the vtable isn't
> >built yet so virtuals behave like non-virtual functions.
> No, it isn't.
> Virtuals behave like non-virtuals only from inside the constructor, and
> even then there are exceptions. Virtuals are still virtuals called from any
> other function, even when the constructor hasn't yet finished.

Seems that we don't have the same thing in mind, see below.

> If the Derived constructor calls Base::function which in turn calls the
> virtual function "virtual_function", the call should be routed to
> Derived::virtual_function, even if the construction is not yet complete.

Of course, but that's not virtual behavior, that "normal" overridden behavior. 
You get the method of the current type you're in, statically determined, not 
dynamically. You'll never go through the vtable as it's not created yet, no 
matter if your method is called directly or not, it doesn't change anything.

What I mean is that if you have a More_Derived class, overriding a virtual, 
and your Derived ctor calls this virtual either directly or not, the 
More_Derived version will *not* be called, only the Derived version.

Anyway, this is starting to look like c.l.c++.moderated, so let's leave it at 
that :-).


More information about the kde-core-devel mailing list