Article View: gnu.g++.bug
Article #780Miscompiled vtbl
From: A.R.Runnalls
Date: Tue, 11 Aug 1992 08:58
Date: Tue, 11 Aug 1992 08:58
63 lines
2788 bytes
2788 bytes
The following program gives the output `I'm an LR' instead of the
correct output `I'm an LR2'. The problem, which appears to be due to
the virtual table for LR2 being wrongly set up, disappears if either the
virtual destructor for class L is removed, or if a virtual destructor is
added to class R.
Environment: g++ 2.2.2 on Sparc running SunOS 4.
Script started on Tue Aug 11 09:49:52 1992
vtblbug% cat -n vtblbug.cc
1 // vtblbug.cc
2
3 #include <iostream.h>
4
5 class L {
6 public:
7 virtual ~L() {}
8 virtual void whatami(ostream& stream = cout) const
9 {stream << "I'm an L" << endl;}
10 };
11
12 class R {
13 public:
14 virtual void whatami(ostream& stream = cout) const
15 {stream << "I'm an R" << endl;}
16 };
17
18 class LR : public L, public R {
19 public:
20 void whatami(ostream& stream = cout) const
21 {stream << "I'm an LR" << endl;}
22 };
23
24 class LR2 : public LR {
25 public:
26 void whatami(ostream& stream = cout) const
27 {stream << "I'm an LR2" << endl;}
28 };
29
30 main()
31 {LR2 node;
32 L *node_ptr = &node;
33 node_ptr->whatami();}
vtblbug% make vtblbug
rm -f vtblbug.o
g++ -c -g -v -Wall vtblbug.cc
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/specs
gcc version 2.2.2
/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix -g -Wall vtblbug.cc /usr/tmp/cca19588.i
GNU CPP version 2.2.2 (sparc)
/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/cc1plus /usr/tmp/cca19588.i -quiet -dumpbase vtblbug.cc -g -Wall -version -o /usr/tmp/cca19588.s
GNU C++ version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
as -o vtblbug.o /usr/tmp/cca19588.s
g++ -g -v -o vtblbug vtblbug.o
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/specs
gcc version 2.2.2
/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/ld -e start -dc -dp -o vtblbug /lib/crt0.o -L/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2 -L/usr/local/lib vtblbug.o -lg++ -lgcc -lc -lg -lgcc
vtblbug% !$
vtblbug
I'm an LR
vtblbug% exit
vtblbug%
script done on Tue Aug 11 09:51:26 1992
Technical Details
Message-ID:
<5@larch.ukc.ac.uk>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!ukc.ac.UK!arrShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!ukc.ac.UK!arr From: arr@ukc.ac.UK (A.R.Runnalls) Subject: Miscompiled vtbl Message-ID: <5@larch.ukc.ac.uk> Sender: gnulists@ai.mit.edu Organization: Computing Lab, University of Kent at Canterbury, UK. Distribution: gnu Date: Tue, 11 Aug 1992 08:58:12 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 64