🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1651

Virtual Destructor Bug in 1.31.0

#1651
From: kim
Date: Wed, 25 Jan 1989 19:39
41 lines
1472 bytes
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 <stdio.h>

    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.
Technical Details
Message-ID: <8901251939.AA08887@sfu_cmpt.cs.sfu.ca>
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!mcdchg!rutgers!ukma!tut.cis.ohio-state.edu!cs.sfu.ca!kim

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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