Title
Sequence points and new-expressions
Status
nad
Section
7.6.2.8 [expr.new]
Submitter
Herb Sutter

Created on 1999-06-20.00:00:00 last changed 294 months ago

Messages

Date: 1999-10-15.00:00:00

Rationale (10/99): Even in the "traditional" ordering of the calls to allocation functions and constructors, memory can still leak. For instance, if T1 were successfully constructed and then the construction of T2 were terminated by an exception, the memory for T1 would be lost. Programmers concerned about memory leaks will avoid this kind of construct, so it seems unnecessary to provide special treatment for it to avoid the memory leaks associated with one particular implementation strategy.

Date: 2022-02-18.07:47:23

Clause 7 [expr] paragraph 4 appears to grant an implementation the right to generate code for a function call like

    f(new T1, new T2)
in the order
  • allocate memory for the T1 object
  • allocate memory for the T2 object
  • call the T1 constructor
  • call the T2 constructor
  • call f
However, 7.6.2.8 [expr.new] paragraph 17 seems to require the deallocation of the storage for an object only if part of the initialization of that object terminates with an exception. Given the ordering above, this specification would appear to allow the memory for the T2 object to be leaked if the T1 constructor throws an exception.

Suggested resolution: either forbid the ordering above or expand the requirement for reclaiming storage to include exceptions thrown in all operations between the allocation and the completion of the constructor.

Rationale (10/99): Even in the "traditional" ordering of the calls to allocation functions and constructors, memory can still leak. For instance, if T1 were successfully constructed and then the construction of T2 were terminated by an exception, the memory for T1 would be lost. Programmers concerned about memory leaks will avoid this kind of construct, so it seems unnecessary to provide special treatment for it to avoid the memory leaks associated with one particular implementation strategy.

History
Date User Action Args
2000-02-23 00:00:00adminsetmessages: + msg279
2000-02-23 00:00:00adminsetstatus: open -> nad
1999-06-20 00:00:00admincreate