From 6839793280573447865 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,db4807a3f0a1e742 X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 1994-07-27 00:14:58 PST Newsgroups: comp.std.c++ Path: nntp.gmd.de!xlink.net!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!yeshua.marcam.com!charnel.ecst.csuchico.edu!csusac!csus.edu!netcom.com!rfg From: rfg@netcom.com (Ronald F. Guilmette) Subject: Re: Multiple inheritance and delete Message-ID: Organization: Netcom Online Communications Services (408-241-9760 login: guest) References: Date: Wed, 27 Jul 1994 06:51:50 GMT Lines: 50 In article immel@chord.centerline.com (Mark Immel) writes: > >C++ gurus and standard committee -- > >I asked about the following code a few days ago. The problem is that the >call to delete b calls free with a bad address; this is a particularly nasty >silent failure -- often the program will crash much later. Many of you >commented that giving B a virtual destructor will fix the problem; that's >true. However, the WP 5.3.5 (26 May, 1994 version) implies that my code >is legal: > > > struct A {}; > struct B {}; > struct C: A, B {}; > > void foo() > { > B* b = new C; > delete b; > } > >5.3.5 paragraph 2: > > "The value of the operand of delete must be a pointer to a non-array > object created by a new-expression without a new-placement specification, > or a pointer to a subobject representing a base class of such an object." > >5.3.5 paragraph 3: > > "If the static type of the operand is different from its dynamic type *AND > THE CLASS OF THE COMPLETE OBJECT HAS A DESTRUCTOR*, the static type must > have a virtual destructor, or the result is undefined." (emphasis mine) I hope that I'm not the only one who notices the sloppy wording here. In the above example, the static type of the operand of the `delete' operator is type B*. (One assumes that that is it's dynamic type also.) 5.3.5p3 needs to be fixed to talk about the ``pointed at'' type of the operand, rather that the type of the operand itself. (Note that the operand type for a `delete' must be a pointer type, and pointer types NEVER have virtual destructors. It is even arguable whether pointer types have destructors at all!) -- -- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting ------------------- ---- domain addr: rfg@netcom.com ----------- Purveyors of Compiler Test ---- ---- uucp addr: ...!uunet!netcom!rfg ------- Suites and Bullet-Proof Shoes -