Article View: gnu.g++.bug
Article #2177virtual function bug...
From: Brian G. Anderson
Date: Sat, 03 Feb 1990 22:42
Date: Sat, 03 Feb 1990 22:42
91 lines
3608 bytes
3608 bytes
I just got bitten by a bug in virtual functions with virtual base classes.
The code follow along with the segmentation error reported when run under
gdb. The code should print out:
four
two
hello]one
two
but as one can see when examining the run output it gets to "hello]one"
before jumping to a non-existent location. The program seems correct to
me. I'm dead in the water until I can figure out how to correct this.
Am I doing something wrong? If I am why, isn't the compiler telling me?
If I am not, is there a patch to fix this problem? Help!
-Brian G. Anderson New York University
andersnb@cs.nyu.edu
--------the code----------
#include <stream.h>
class bottom {
public:
char* hold;
bottom(char* txt) { hold = txt; }
virtual void one() const = 0;
};
class leftone: public virtual bottom {
public:
virtual void two() const = 0;
void one() const { cout << hold << "] one\n"; two(); }
};
class lefttwo: public leftone {
public:
void two() const { cout << "two\n"; }
};
class right: public virtual bottom {
public:
void three() const { cout << "three\n"; one(); }
};
class top: public right, public lefttwo {
public:
top(char* txt): bottom(txt) {};
void four() const { cout << "four\n"; two(); one(); }
};
main() {
top x("hello");
x.four();
}
-------compile and run--------
(shasha)% g++ -g -v test.cc
g++ version 1.36.4 (based on GCC 1.36.93)
/usr/src/local/usr/local/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ test.cc /usr/tmp/cca07957.cpp
GNU CPP version 1.36.92
/usr/src/local/usr/local/lib/gcc-cc1plus /usr/tmp/cca07957.cpp -quiet -dumpbase test.cc -g -version -o /usr/tmp/cca07957.s
GNU C++ version 1.36.4 (based on GCC 1.36.93) (sparc) compiled by GNU C version 1.36.92.
default target switches: -mfpu -mepilogue
/usr/src/local/usr/local/lib/gcc-as -o test.o /usr/tmp/cca07957.s
/usr/src/local/usr/local/lib/gcc-ld -e start -dc -dp -Bstatic /lib/crt0.o test.o -lg++ /usr/src/local/usr/local/lib/gcc-gnulib -lg -lc
(shasha)% gdb a.out
GDB 3.4, Copyright (C) 1989 Free Software Foundation, Inc.
There is ABSOLUTELY NO WARRANTY for GDB; type "info warranty" for details.
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "info copying" to see the conditions.
Reading symbol data from /shasha/andersnb/plinda/a.out...done.
Type "help" for a list of commands.
(gdb) run
Starting program: a.out
four
two
hello] one
Program received signal 11, Segmentation fault
0x0 in _DYNAMIC ()
(gdb) quit
The program is running. Quit anyway? (y or n) y
(shasha)% exit
(shasha)%
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Brian G. Anderson |
NYU Ultracomputer Research Project |||
715 Broadway Rm. 1006 |||||
New York, NY 10003 |||||
(212) 998-3346 --- //\ ---
arpa: andersnb@cmcl2 ----/ \----
uucp: {ihnp4,seismo}!cmcl2!andersnb ---- ----
Technical Details
Message-ID:
<9002032242.AA01402@cs.NYU.EDU>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!CS.NYU.EDU!andersnbShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!CS.NYU.EDU!andersnb From: andersnb@CS.NYU.EDU (Brian G. Anderson) Newsgroups: gnu.g++.bug Subject: virtual function bug... Message-ID: <9002032242.AA01402@cs.NYU.EDU> Date: 3 Feb 90 22:42:41 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 91