This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 112e. See for the official list.


2625. Deletion of pointer to out-of-lifetime object

Section: 6.7.3  []     Status: C++23     Submitter: Blacktea Hamburger     Date: 2022-08-27

[Accepted as a DR at the November, 2022 meeting.]


struct S {};

int main() {
  S* p = new S;
  delete p;

This code appears to be allowed per 6.7.3 [] bullet 6.1:

The program has undefined behavior if:

However, this calls the (trivial) destructor on *p twice. Invoking a non-static member function of an out-of-lifetime object is generally undefined behavior per 6.7.3 [] bullet 6.2 and 6.7.3 [] bullet 7.2. The rules ought to be consistent.

Proposed resolution (approved by CWG 2022-10-07):

Change in 6.7.3 [] bullet 6.1 as follows:

The program has undefined behavior if: