Path: utzoo!telly!ddsw1!mcdchg!rutgers!ukma!tut.cis.ohio-state.edu!cs.sfu.ca!kim From: kim@cs.sfu.ca Newsgroups: gnu.g++.bug Subject: Virtual Destructor Bug in 1.31.0 Message-ID: <8901251939.AA08887@sfu_cmpt.cs.sfu.ca> Date: 25 Jan 89 19:39:00 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 41 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; } The semantics of C++ indicates that the base class destructor is executed after the derived class destructor code is executed. See: Stroustrup, The C++ Programming Language, p. 290 Stroustrup, The Evolution of C++ 1985 to 1987, Proceedings of the Usenix C++ Workshop, 1987, p. 10 The generated g++ code apparently calls the base class destructor via the virtual table, rather than directly. This, of course, results in the infinite recursion.