Topic: Exception in c'tor of dynamically alloc'd array


Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1995/05/11
Raw View
In article <3oqlhf$9qo@ritz.cec.wustl.edu> jaf3@ritz.cec.wustl.edu
(John Andrew Fingerhut) writes:

|> In the latest draft under section 15.2 (Constructors and Destructors),
|> paragraph 2 reads:

|> 2 An object that is partially constructed will have destructors executed
|>   only for its fully constructed sub-objects.  Should a constructor  for
|>   an  element  of  an  automatic array throw an exception, only the con-
|>   structed elements of that array will be destroyed.  If the  object  or
|>   array  was allocated in a new-expression, the storage occupied by that
|>   object is sometimes deleted also (_expr.new_).

|> What does "sometimes" mean here?

It means `sometimes'.  The details are in chapter 5 (reference
_expr.new_).  Basically, if the object or the array was allocated with
the standard new syntax, it is deleted; if it was allocated with
placement new syntax, a corresponding `placement delete' (another new
feature) is looked up.  If none is found, the memory is not deleted.

This is basically because of the following:

 class X { /* ... */ } ;

 char            buf[ sizeof( X ) ] ;
 new ( buf ) X ;                 //  Ctor of X throws an exception.

You really don't want to call operator delete( buf ) in this case, do
you?
--
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                              -- Beratung in industrieller Datenverarbeitung







Author: jaf3@ritz.cec.wustl.edu (John Andrew Fingerhut)
Date: 1995/05/10
Raw View
In the latest draft under section 15.2 (Constructors and Destructors),
paragraph 2 reads:

2 An object that is partially constructed will have destructors executed
  only for its fully constructed sub-objects.  Should a constructor  for
  an  element  of  an  automatic array throw an exception, only the con-
  structed elements of that array will be destroyed.  If the  object  or
  array  was allocated in a new-expression, the storage occupied by that
  object is sometimes deleted also (_expr.new_).

What does "sometimes" mean here?

--
Stephen Gevers
sg3235@shelob.sbc.com





Author: jaf3@ritz.cec.wustl.edu (John Andrew Fingerhut)
Date: 1995/05/10
Raw View
In article <3oqqut$bsa@engnews2.Eng.Sun.COM>,
Steve Clamage <clamage@Eng.Sun.COM> wrote:
:In article 9qo@ritz.cec.wustl.edu, jaf3@ritz.cec.wustl.edu (John Andrew Fingerhut) writes:
:>In the latest draft under section 15.2 (Constructors and Destructors),
:>paragraph 2 reads:
:>
:>2 An object that is partially constructed will have destructors executed
:>  only for its fully constructed sub-objects.  Should a constructor  for
:>  an  element  of  an  automatic array throw an exception, only the con-
:>  structed elements of that array will be destroyed.  If the  object  or
:>  array  was allocated in a new-expression, the storage occupied by that
:>  object is sometimes deleted also (_expr.new_).
:>
:>What does "sometimes" mean here?
:
:Follow the pointer to _expr.new_. If, e.g., the object was created using
:a "placement new", it won't be deleted.
:
:
:
:---
:Steve Clamage, stephen.clamage@eng.sun.com
:
:

In [expr.new]

18If the constructor throws 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 declaration of
  that placement operator new,  then  the  matching  placement  operator
  delete shall be called (_basic.stc.dynamic.deallocation_).

I don't see an "otherwise" in this section.  Should the standard specify
here that no deallocation function is called when the lookup fails?
--
Stephen Gevers
sg3235@shelob.sbc.com