Path: utzoo!utgpu!watmath!uunet!tut.cis.ohio-state.edu!mailrus!eecae!netnews.upenn.edu!rutgers!ucsd!orion.cf.uci.edu!uci-ics!siam.ics.uci.edu!schmidt From: schmidt@siam.ics.uci.edu (Doug Schmidt) Newsgroups: gnu.g++.bug Subject: Re: Virtual Destructor Bug in 1.31.0 Message-ID: <5394@paris.ics.uci.edu> Date: 25 Jan 89 21:51:25 GMT References: <8901251939.AA08887@sfu_cmpt.cs.sfu.ca> Sender: news@paris.ics.uci.edu Reply-To: Doug Schmidt Distribution: gnu Organization: University of California at Irvine: ICS Dept. Lines: 56 In article <8901251939.AA08887@sfu_cmpt.cs.sfu.ca> kim@cs.sfu.ca writes: ++In using g++ (version 1.31.0) we have encountered a serious problem in the ++code generated for virtual destructors. ++ ++Criteria: The following code results in runtime infinite recursion on ~derived: ++ ++ #include ++ ++ class base ++ { ++ base(); ++ virtual ~base(); ++ }; ++ ++ inline base::base() {} ++ inline base::~base() {} ++ ++ class derived : base ++ { ++ derived(); ++ ~derived(); ++ }; ++ ++ inline derived::derived() : () {} ++ inline derived::~derived() { fputc('*',stderr); } ++ ++ main() ++ { ++ derived a; ++ } ++ This bug is fixed in GNU G++ 1.32. However, your code is also incorrect, since the constructor's and destructor's are declared in the ``private'' section of class base and class derived, by the default visibility rules. Here's what a beta version of g++ 1.32.1 says: ---------------------------------------- In function struct derived *derived::derived (): virt-dest-bug.1.32.cc:9: the constructor struct base *base::base () is private virt-dest-bug.1.32.cc:18: no default constructor defined for type `base' In function int main (): virt-dest-bug.1.32.cc:18: the constructor struct derived *derived::derived () is private virt-dest-bug.1.32.cc:23: no default constructor defined for type `derived' ---------------------------------------- When I added the keyword ``public'' to the classes the program ran as expected. Doug -- schmidt@ics.uci.edu (ARPA) | Per me si va nella citta' dolente. office: (714) 856-4043 | Per me si va nell'eterno dolore. | Per me si va tra la perduta gente. | Lasciate ogni speranza o voi ch'entrate.