Bug 19604 - vtable error with virtual inheritance and arrays
Summary: vtable error with virtual inheritance and arrays
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-24 14:28 UTC by Webmyster
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
vtable error with virtual inheritance and tables (286 bytes, application/octet-stream)
2005-01-24 14:31 UTC, Webmyster
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Webmyster 2005-01-24 14:28:47 UTC
I don't know if it's a bug in g++ or a lack in the specifications of C++ ...

I define two classes, one inherited from the second. I allocate a table of the
child, I give it to a fonction that waits for the parent class.

Inside this function, when I try to access virtual functions of an element of
the table other than the first, I get a segfault.
It seems to be that in this function, the size of each element of the table is
considered to be the one of the parent but not the one of the child. That
induces a memory shift that segfault when trying to accessing the vtable ...

Is there the size of the object inside the vtable ?
Comment 1 Webmyster 2005-01-24 14:31:52 UTC
Created attachment 8053 [details]
vtable error with virtual inheritance and tables

This file shows two things :
* the size of one element is different according to the context (parent class
or child class) ;
* this difference induce a segfault when trying to acces virtual function
"VirtualAdresse()".
Comment 2 Andrew Pinski 2005-01-24 14:37:15 UTC
I think this is invalid and here is why?
Basically the sizeof (A) is smaller than sizeof(B).
But if you convert from B* to A* you cannot access the second element any more.
Comment 3 Webmyster 2005-01-24 14:53:55 UTC
(In reply to comment #2)
> I think this is invalid and here is why?
> Basically the sizeof (A) is smaller than sizeof(B).
> But if you convert from B* to A* you cannot access the second element any more.

I'm agree it's not a conventional use of inheritance and tables. But it may be
valid.
Where could I find the C++ specifications used to implement g++, to get a valid
solution to my problem ?

Moreover, I would like to have a warning during the compilation. I think the
compiler can warning on each call of non first element of a table of classes
containing vtable.
Comment 4 Wolfgang Bangerth 2005-01-26 04:25:50 UTC
You are accessing something here  
  var[1].adresse() 
that definitely is not an A, but sitting somewhere between other 
objects. That's definitely not allowed. 
 
W.