🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1082

missing virtual table for objects with virtual function and base class

#1082
From: Paul Eggert
Date: Fri, 06 Nov 1992 03:29
47 lines
1739 bytes
GCC 2.3.1 sometimes forgets to initialize the virtual table for an object with
a virtual function and virtual base class.  In the following example (SunOS
4.1.2, sparc), y's virtual table is never initialized, leading to a bus error
when it's used.

$ cat t.cc
class R {};

class T : virtual public R {
 public:
    T() {}
    virtual void v() {}
    void f() { v(); }
};

T x;

int main()
{
    T y(x);
    y.f();
    return 0;
}
$ gcc -g t.cc
$ ./a.out
Bus error - core dumped
$ gdb a.out
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.7, Copyright 1992 Free Software Foundation, Inc...
(gdb) run
Starting program: /tmp/a.out 

Program received signal 10, Bus error
0x2300 in T::f (this=0xf7fffcd0) at t.cc:7
7	    void f() { v(); }
(gdb) up
#1  0x2358 in main () at t.cc:15
15	    y.f();
(gdb) display x
1: x = {<R> = {}, _vb$R = 0x40c8, _vptr$FOO = 0x40d0 <T virtual table>}
(gdb) display y
2: y = {<R> = {}, _vb$R = 0xf7fffcd8, _vptr$FOO = 0x8103010b}
(gdb) 

The 0x8103010b is uninitialized garbage.
Technical Details
Message-ID: <9211060329.AA03580@farside.twinsun.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert
From: eggert@twinsun.COM (Paul Eggert)
Subject: missing virtual table for objects with virtual function and base class
Message-ID: <9211060329.AA03580@farside.twinsun.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Fri, 6 Nov 1992 03:29:44 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 48