Path: utzoo!attcan!uunet!lll-winken!csd4.milw.wisc.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!pp!riunite!rfg From: rfg@riunite.ACA.MCC.COM (Ron Guilmette) Newsgroups: comp.lang.c++ Subject: Re: Virtual destructors Keywords: virtual destructor portability Message-ID: <101@riunite.ACA.MCC.COM> Date: 1 Mar 89 23:24:01 GMT References: <551@hrc63.co.uk> <1430@cod.NOSC.MIL> Reply-To: rfg@riunite.UUCP (Ron Guilmette) Organization: MCC Austin, Texas Lines: 42 In article <1430@cod.NOSC.MIL> mball@cod.nosc.mil.UUCP (Michael S. Ball) writes: >In article <551@hrc63.co.uk> pj@hrc63.co.uk (Mr P Johnson "Baddow") writes: >>In Oregon C++ (for Suns) v 1.1, it is possible to declare the base destructor >>as virtual. This then ensures that the appropriate destructor is called for >>any derived classes provided that the _derived_class_has_a_destructor_. If >>the derived class has no explicit destructor then any member destructors will >>not be called (rather than being called implicitly as they would be normally). > >I believe this is a bug. I'm not sure what the "correct" semantics are myself, but I don't think it is a bug. I say that only because I have just recently been looking into the handling of "virtual" in GNU G++ (and in particular the handling of "virtual" for destructors) and I can tell you that G++ seems to do pretty much the same thing as described above. That is to say, if you have a base class which has an explicitly virtual destructor, then the destructor will get a entry in the vtable for that class. Also, any classes derived from such a class also (apparently) have entries for *their* destructors put into *their* vtables (in the same slot number). This seems to be true regardless of whether or not the destructors in the derived classes explicitly have the keyword "virtual" in their declarations. Thus, it seems that these destructors (in the derived classes) in effect become "implicitly" virtual. I also assume (but I have not yet checked) that (in G++) the destruction of an object which has either an explicitly or implicitly virtual destructor will be forced to go "indirect" through the vtable for that object. If that is true, then that means that the "appropriate destructor" should get called for all such objects regardless of whether or not the compiler can "statically" determine the actual class of an object which is being destroyed. // Ron Guilmette - MCC - Experimental (parallel) Systems Kit Project // 3500 West Balcones Center Drive, Austin, TX 78759 - (512)338-3740 // ARPA: rfg@mcc.com // UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg -- // Ron Guilmette - MCC - Experimental (parallel) Systems Kit Project // 3500 West Balcones Center Drive, Austin, TX 78759 - (512)338-3740 // ARPA: rfg@mcc.com // UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg