Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!know!ladcgw.ladc.bull.com!pluto.hemel.bull.co.uk!pmoore From: pmoore@hemel.bull.co.uk (Paul Moore) Newsgroups: comp.lang.c++ Subject: conditional scope and destructors Message-ID: <1990Nov9.151803.11426@hemel.bull.co.uk> Date: 9 Nov 90 15:18:03 GMT Organization: Bull HN UK Lines: 26 This is a problems I had writing dos code with zortech 2.1 but it is a general problem with c++ - something is not tightly defined. Problem:- if an object is only created conditionally in a function should its destructor be called at function exit? Example:- func(..) ..... if (foo==bar) return(z); ..... object obj1; .... } If foo does equal bar then obj is not created - should its destructor be called when the return is done? Zortech 2.1 does call it. It seems to me this is a bug , but Strousop doesnt really discuss this point as far as I can see. What do other compilers do? (The above example is trivial - the declaration of obj could be placed at the start of func. This is not the case where the constructor takes arguments that must be calculated before the declaration). The actual problem I had was that the filebuf destructor blew up when I had a conditional declaration of filebuf that wasnt invoked.