Topic: Q: operator new and exceptions
Author: mishad@iplbath.com (Misha Dorman)
Date: 1996/10/28 Raw View
The Jan 96 draft says (in expr.new [18]):
> If the constructor exits using an exception and the new-expression
> contains a new-placement, a name lookup is performed on the name of
> operator delete in the scope of this new-expression. If the lookup
> succeeds and exactly one of the declarations found matches the decla-
> ration of that placement operator new, then the matching placement
> operator delete shall be called (_basic.stc.dynamic.deallocation_).
I can't find anything to say what happens in the array case when one of
the constructors throws an exception: do the already constructed elements
get destructed before the memory is freed?
Thanks for any light you can shed on this...
--
Misha Dorman email: mishad@iplbath.com
Software Products Group WWW: http://www.iplbath.com
IPL Information Processing Ltd Tel: +44 (0)1225 444888
Eveleigh House, Grove Street, Bath BA1 5LR, England
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/11/01 Raw View
mishad@iplbath.com (Misha Dorman) writes:
>The Jan 96 draft says (in expr.new [18]):
>
>> If the constructor exits using an exception and the new-expression
>> contains a new-placement, a name lookup is performed on the name of
>> operator delete in the scope of this new-expression. If the lookup
>> succeeds and exactly one of the declarations found matches the decla-
>> ration of that placement operator new, then the matching placement
>> operator delete shall be called (_basic.stc.dynamic.deallocation_).
>
>I can't find anything to say what happens in the array case when one of
>the constructors throws an exception: do the already constructed elements
>get destructed before the memory is freed?
The Sept 96 draft doesn't say anything about it either, but it does say
that in the array case, a name lookup is performed on the destructor,
which seems like a strong hint.
If the objects are not destroyed implicitly by the compiler, then there
is in general no way for the programmer to delete them. So I'm sure
that the already constructed elements must be destroyed by the
compiler. Hopefully the wording in the draft will be fixed to reflect
this sometime soon.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]