Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sdd.hp.com!decwrl!bacchus.pa.dec.com!decvax.dec.com!zinn!nuucp From: mjv@objects.mv.com (Michael J. Vilot) Newsgroups: comp.lang.c++ Subject: Re: undesired optimiztion (was C++ coding standards) Message-ID: <906@zinn.MV.COM> Date: 2 Sep 90 19:58:40 GMT Sender: nuucp@zinn.MV.COM Lines: 17 >From Steve Clamage: > E&S section 3.5: > "A named local object may not be destroyed before the end > of its block Note the word `named' in this phrase, it's important. I had a fragment of code that was too clever by half: { Lock(*this); // constructor acquires lock // some action } // destructor releases lock g++ optimized away the unnamed temporary, calling the destructor immediately rather than at the end of the block. This is perfectly legal, and was solved by explicitly naming the Lock object. -- Mike Vilot, ObjectWare Inc, Nashua NH mjv@objects.mv.com (UUCP: ...!decvax!zinn!objects!mjv)