Document number:  P2313R0
Date:  2021-02-12
Project:  Programming Language C++
Reference:  ISO/IEC IS 14882:2017
Reply to:  William M. Miller
 Edison Design Group, Inc.

Core Language Working Group "tentatively ready" Issues for the February, 2021 meeting

References in this document reflect the section and paragraph numbering of document WG21 N4868.

2470. Multiple array objects providing storage for one object

Section: 6.7.2  [intro.object]     Status: tentatively ready     Submitter: Andrey Erokhin     Date: 2021-01-29

According to 6.7.2 [intro.object] paragraph 3,

If a complete object is created ( []) 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 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?

Proposed resolution (February, 2021):

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