Title
Use of pointers to deallocated storage
Status
cd3
Section
6.7.6.5.3 [basic.stc.dynamic.deallocation]
Submitter
Herb Sutter

Created on 2007-02-27.00:00:00 last changed 131 months ago

Messages

Date: 2014-03-03.00:00:00

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.

Date: 2007-04-15.00:00:00

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.

Date: 2022-11-20.07:54:16

Any use of a pointer to deleted storage, even if the pointer is not dereferenced, produces undefined behavior (6.7.6.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.)

History
Date User Action Args
2014-03-03 00:00:00adminsetmessages: + msg4971
2014-03-03 00:00:00adminsetstatus: extension -> cd3
2007-05-06 00:00:00adminsetmessages: + msg1511
2007-05-06 00:00:00adminsetstatus: open -> extension
2007-02-27 00:00:00admincreate