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

Thiago Macieira thiago.macieira at kdemail.net
Mon Sep 20 00:46:24 BST 2004


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.

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.

The bug here happens because the wrong thunk is called, rendering an invalid 
"this" pointer inside Derived::virtual_function. This only happens if Base 
is a non-primary virtual base.

-- 
  Thiago Macieira  -  Registered Linux user #65028
   thiago (AT) macieira (DOT) info
    ICQ UIN: 1967141   PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20040919/2ef351bb/attachment.sig>


More information about the kde-core-devel mailing list