Title
Storage duration of implicitly created objects
Status
drwp
Section
6.7.5 [basic.stc]
Submitter
Andrey Erokhin

Created on 2022-02-17.00:00:00 last changed 4 months ago

Messages

Date: 2024-01-21.13:30:12

Proposed resolution (approved by CWG 2024-01-19):

  1. Change in 6.7.5.1 [basic.stc.general] paragraph 2 as follows:

    Static, thread, and automatic storage durations are associated with objects introduced by declarations (6.2 [basic.def]) and implicitly created by the implementation with temporary objects (6.7.7 [class.temporary]). The dynamic storage duration is associated with objects created by a new-expression (7.6.2.8 [expr.new]) or with implicitly created objects (6.7.2 [intro.object]).
Date: 2023-12-15.00:00:00

Additional note (December, 2023)

The approach outlined above is incomplete and the wrong direction. The concept of storage duration determines when an object is created and destroyed; for dynamic storage duration, the object is created and destroyed by explicit program action.

Date: 2024-03-15.00:00:00

[Accepted as a DR at the March, 2024 meeting.]

In subclause 6.7.2 [intro.object] paragraph 10, operations implicitly creating objects are defined:

Some operations are described as implicitly creating objects within a specified region of storage. For each operation that is specified as implicitly creating objects, that operation implicitly creates and starts the lifetime of zero or more objects of implicit-lifetime types (6.8.1 [basic.types.general]) in its specified region of storage if...

However, the standard does not specify the storage duration that such an implicitly-created object has; this new method of object creation is not mentioned in 6.7.5.1 [basic.stc.general] paragraph 2:

Static, thread, and automatic storage durations are associated with objects introduced by declarations (6.2 [basic.def]) and implicitly created by the implementation (6.7.7 [class.temporary]). The dynamic storage duration is associated with objects created by a new-expression (7.6.2.8 [expr.new]).

With the exception of malloc, the storage duration should probably be that of the object providing storage (if any), similar to the provision for subobjects in 6.7.5.6 [basic.stc.inherit]:

The storage duration of subobjects and reference members is that of their complete object (6.7.2 [intro.object]).

The storage duration of an object created by a non-allocating form of an allocation function (17.6.3.4 [new.delete.placement]) should be treated similarly.

Possible resolution [SUPERSEDED]:

  1. Change in 6.7.2 [intro.object] paragraph 13 as follows:

    Any implicit or explicit invocation of a function named operator new or operator new[] implicitly creates objects with dynamic storage duration in the returned region of storage and returns a pointer to a suitable created object.
  2. Change in 6.7.5.1 [basic.stc.general] paragraph 2 as follows:

    Static, thread, and automatic storage durations are associated with objects introduced by declarations (6.2 [basic.def]) and implicitly created by the implementation (6.7.7 [class.temporary]). The dynamic storage duration is associated with objects created by a new-expression (7.6.2.8 [expr.new]) in storage returned by an allocation function (6.7.5.5.2 [basic.stc.dynamic.allocation]) other than a non-allocating form (17.6.3.4 [new.delete.placement]) or by C library memory allocation (20.2.12 [c.malloc]).
  3. Change in 6.7.5.5.2 [basic.stc.dynamic.allocation] paragraph 3 as follows:

    For an allocation function other than a reserved placement allocation function other than a non-allocating form (17.6.3.4 [new.delete.placement]), the pointer returned on a successful call shall represent the address of storage that is aligned as follows:
  4. Change in 6.7.5.6 [basic.stc.inherit] paragraph 1 as follows:

    The storage duration of subobjects and reference members is that of their complete object. The storage duration of an object nested within another object x is the storage duration of x (6.7.2 [intro.object]).
  5. Change in 7.6.2.8 [expr.new] paragraph 9 as follows:

    An object created by a new-expression that invokes an allocation function with a non-allocating form (see below) has the storage duration of the object that used to occupy the region of storage where the new object is created. Objects Any other object created by a new-expression have has dynamic storage duration (6.7.5.5 [basic.stc.dynamic]). [Note 5: The lifetime of such an object is not necessarily restricted to the scope in which it is created. —end note]
  6. Change in 20.2.12 [c.malloc] paragraph 4 as follows:

    These functions implicitly create objects (6.7.2 [intro.object]) with dynamic storage duration in the returned region of storage and return a pointer to a suitable created object. In the case of calloc and realloc, the objects are created before the storage is zeroed or copied, respectively.
History
Date User Action Args
2024-07-20 13:52:34adminsetstatus: dr -> drwp
2024-04-05 21:43:46adminsetstatus: ready -> dr
2024-03-20 14:10:31adminsetstatus: tentatively ready -> ready
2024-01-21 13:30:12adminsetmessages: + msg7572
2024-01-21 13:30:12adminsetstatus: review -> tentatively ready
2024-01-13 13:17:21adminsetmessages: + msg7570
2023-07-03 06:17:18adminsetstatus: drafting -> review
2022-11-20 07:54:16adminsetstatus: open -> drafting
2022-02-17 00:00:00admincreate