Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!van-bc!mdavcr!rdr From: rdr@mdavcr.UUCP (Randolph Roesler) Newsgroups: comp.lang.c++ Subject: Re: lint++ -> really "AutoCodeReview" -- Ideas requested. Message-ID: <701@acrux.mdavcr.UUCP> Date: 12 Dec 89 21:51:32 GMT References: <5457.25845C8E@urchin.fidonet.org> Reply-To: rdr@mdavcr.UUCP (Randolph Roesler) Organization: MacDonald Dettwiler, Richmond, B.C., Canada Lines: 64 In article <5457.25845C8E@urchin.fidonet.org> Roy.Browning@f506.n106.z1.fidonet.org (Roy Browning) writes: > > > ComIdent::~ComIdent() > > { > > if ( string ) > > delete[strlen(string)+1] string; > > } > > > The fix --- delete the copy constructor and replace with an assignment > > one. > >Randolph: > > I have sucessfully used both a copy constructor and an overloading >assignment operator in a test class. However from my limited reading on C++ I >believe your problem is your destructor. From reading Lippman pages 240 & 241 >you are deleting an array of pointers stored in "string" where "[x]" is the >number to "free()". From the source code I've seen all "delete" does is to >call "free()" and pass it a "char *". Telling "delete" there are "[X]" >pointers stored at location "string" should cause some VERY unusual problems >if I'm correct. > > I could use a lint myself, > > Roy Browning > Thanks for the reply Roy. The program is working fine now, so I do not think that the destructor is the problem. My use of delete is symmetric with may use of new. I.e. some_type * xxxx = new some_type [size]; delete [size] xxxx; In this case, some_type is `char', and thus, neither new or delete need to call constructors/destructors. The key passage in the manual is on page 21 (SUN C++ docs, section 5.3.4), which says (much left out): The form delete [ expression ] cast_expression is used to delete arrays.... destructors (if any) ... will be invoked. Still, you bring up a good point. If some_type was orginal typedefined as character, and you left out the [ expression ] construction from the delete statement, everything would probably work out fine. (I guess I should try this !). If, latter, a change my typedefine of some_type to some other type with constructors and destructors, then the code would probably start to fail. Could a tool be written to track varible usage and warn you about this type of situations ? Any more situations like this ? -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It's not the size of your signature that Randy Roesler counts - it's how you use it! MacDonald Dettwiler & Assc. email ...!uunet!van-bc!mdavcr!rdr BC Canada 604-278-3411