c++/8612: Vtable layout: missing vcall offset

grigory@stl.sarov.ru grigory@stl.sarov.ru
Fri Nov 22 11:18:00 GMT 2002


>Number:         8612
>Category:       c++
>Synopsis:       Vtable layout: missing vcall offset
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Nov 17 02:26:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Grigory Zagorodnev
>Release:        3.2
>Organization:
>Environment:
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
>Description:
'C2' is the virtual base of class 'C1' in the given test-case. So the C2-in-C1 virtual table should contains virtual call (vcall) offsets for all virtual functions defined in C2 and it's subobjects.

Class C4 defines virtual function f6 and this class is included twice in the C2 (as direct and indirect non-virtual base). So two vcall entries are expected in the virtual table. However g++ gives only one entry - see vtable layout below.

That should be considered as a bug.

------------------------
The test-case (test.cpp) 
------------------------
struct C4
{
        int m0;
virtual int f6()        { return 4; }
};

struct C7:  C4
{
        int m0;
};

struct C2: C4, C7
{
        int m0;
};

struct C1: virtual C2
{
        short m1;
};

C1 o1;

--------------------
Virtual table layout
--------------------
$ g++ -c -fdump-class-hierarchy test.cpp
$ cat test.cpp.class

Vtable for C1
C1::_ZTV2C1: 10 entries
0     8
4     0
8     &_ZTI2C1
12    8		< -- f6's vcall offset. Why only one?
16    0fffffff8
20    &_ZTI2C1	< -- C2-in-C1 vtable entry point
24    C4::f6()
28    0fffffff0
32    &_ZTI2C1
36    C4::f6()

Class C1
   size=32 align=4
C1 (0x40323200) 0
    vptridx=0 vptr=((&C1::_ZTV2C1) + 12)
  C2 (0x40323240) 8 virtual canonical
      vptridx=4 vbaseoffset=-12 vptr=((&C1::_ZTV2C1) + 24)
    C4 (0x40323300) 8
        primary-for C2 (0x40323240)
    C7 (0x40323280) 16
        vptridx=8 vptr=((&C1::_ZTV2C1) + 36)
      C4 (0x403232c0) 16
          primary-for C7 (0x40323280)
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-prs mailing list