Title
Multiple array objects providing storage for one object
Status
cd6
Section
6.7.2 [intro.object]
Submitter
Andrey Erokhin

Created on 2021-01-29.00:00:00 last changed 20 months ago

Messages

Date: 2021-02-15.00:00:00

Proposed resolution (February, 2021):

Change 6.7.2 [intro.object] bullet 3.3 as follows:

  • there is no smaller array object that satisfies these constraints nested within e.

Date: 2022-05-21.12:38:12

Suggested resolution:

Change 6.7.2 [intro.object] bullet 3.3 as follows:

  • there is no smaller array object that satisfies these constraints nested within e.

Date: 2021-01-29.00:00:00

According to 6.7.2 [intro.object] paragraph 3,

If a complete object is created (7.6.2.8 [expr.new]) in storage associated with another object e of type “array of N unsigned char” or of type “array of N std::byte” (17.2.1 [cstddef.syn]), that array provides storage for the created object if:

  • the lifetime of e has begun and not ended, and

  • the storage for the new object fits entirely within e, and

  • there is no smaller array object that satisfies these constraints.

The intent of the third bullet is to select a unique array object among those satisfying the first two bullets. However, it is possible to have multiple array objects of the same size satisfying the first two bullets. For example:

  unsigned char buffer[8];
  struct OhNo { std::byte data[8]; };
  static_assert(sizeof(OhNo) == 8 && sizeof(int) == 4);
  OhNo *p = new (buffer) OhNo;   // buffer provides storage for OhNo
  int *q = new (p->data) int;    // who provides storage for this?
  int *r = new (buffer + 4) int; // who provides storage for this?
History
Date User Action Args
2022-08-19 07:54:33adminsetstatus: drwp -> cd6
2022-05-21 12:38:12adminsetmessages: + msg6832
2021-11-15 00:00:00adminsetstatus: dr -> drwp
2021-02-24 00:00:00adminsetstatus: tentatively ready -> dr
2021-02-17 00:00:00adminsetmessages: + msg6484
2021-01-29 00:00:00admincreate