This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 110d. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2023-02-24


623. Use of pointers to deallocated storage

Section: 6.7.5.5.3  [basic.stc.dynamic.deallocation]     Status: CD3     Submitter: Herb Sutter     Date: 27 February 2007

Any use of a pointer to deleted storage, even if the pointer is not dereferenced, produces undefined behavior (6.7.5.5.3 [basic.stc.dynamic.deallocation] paragraph 4) . The reason for this restriction is that, on some historical architectures, deallocating an object might free a memory segment, resulting in a hardware exception if a pointer referring to that segment were loaded into a pointer register, and on those architectures use of a pointer register for moving and comparing pointers was the most efficient mechanism for these operations.

It is not clear whether current or foreseeable architectures still require such a draconian restriction or whether it is feasible to relax it only to forbid a smaller range of operations. Of particular concern is the use of atomic pointers, which might be used in race conditions involving deallocation, where the loser of the race might encounter this undefined behavior.

(See also issue 312.)

Rationale (April, 2007):

The current specification is clear and was well-motivated. Analysis of whether this restriction is still needed should be done via a paper and discussed in the Evolution Working Group rather than being handled by CWG as an issue/defect.

Additional note, February, 2014:

This issue was resolved by the resolution of issue 616, which made use of a pointer to deleted storage implementation-defined behavior.