Title
Mishandling of placement-new in lifetime rules
Status
open
Section
6.8.4 [basic.life]
Submitter
Richard Smith

Created on 2025-02-26.00:00:00 last changed yesterday

Messages

Date: 2025-09-13.07:51:53

Suggested resolution:

Change in 6.8.4 [basic.life] paragraph 7 as follows:

Before the lifetime of an object has started but after the storage which the object will occupy has been allocated [ Footnote: ...] or, after the lifetime of an object has ended and before the storage which the object occupied is reused or released, any pointer that represents the address of the storage location where the object will be or was located points to the object may be used but only in limited ways. ...
Date: 2025-02-26.00:00:00

(Split off from issue 3001.)

The out-of-lifetime rules mishandle this example:

  int a;
  int *p = &a;
  *p = 1;       // #1
  new (p) int;

This code has undefined behavior because, according to the wording specifying "represents the address", p is used to access the pointed-to object at #1 before its lifetime starts in the following line.

History
Date User Action Args
2025-09-13 07:51:53adminsetmessages: + msg8101
2025-02-26 00:00:00admincreate