Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!arkesden.eng.sun.com!tiemann From: tiemann@arkesden.eng.sun.com (Michael Tiemann) Newsgroups: gnu.g++.bug Subject: virtual function bug... Message-ID: <9002050418.AA21978@arkesden.sun.com> Date: 5 Feb 90 04:18:42 GMT References: <9002032242.AA01402@cs.NYU.EDU> Sender: daemon@tut.cis.ohio-state.edu Reply-To: tiemann@sun.com Distribution: gnu Organization: GNUs Not Usenet Lines: 89 Date: Sat, 3 Feb 90 17:42:41 -0500 From: andersnb@cs.nyu.edu (Brian G. Anderson) 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 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(); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 ---- ---- Here's a patch to try: arkesden% diff -c2 cplus-search.c~ cplus-search.c *** cplus-search.c~ Fri Jan 26 06:31:53 1990 --- cplus-search.c Sun Feb 4 19:53:04 1990 *************** *** 2677,2680 **** --- 2677,2687 ---- } ok: + if (CLASSTYPE_OFFSET (this_context) != integer_zero_node) + { + tree offset_entry = CONSTRUCTOR_ELTS (MI_VMATRIX (row, col)[2]); + TREE_VALUE (offset_entry) + = genop (PLUS_EXPR, TREE_VALUE (offset_entry), + CLASSTYPE_OFFSET (this_context)); + } MI_VMATRIX (row, col)[0] = 0; arkesden% Michael