Title
Allocating memory for exception objects
Status
drafting
Section
6.7.6.5.2 [basic.stc.dynamic.allocation]
Submitter
Jonathan Wakely

Created on 2015-01-20.00:00:00 last changed 95 months ago

Messages

Date: 2016-02-15.00:00:00

Notes from the February, 2016 meeting:

The prohibition of using an allocation function appears only in a note, although there is a normative reference to the rule in 14.2 [except.throw] paragraph 4. CWG was in favor of retaining the prohibition of using a C++ allocation function for the memory of an exception object, with the implicit understanding that use of malloc would be permitted. The resolution for this issue should delete the note and move the prohibition to normative text in the relevant sections.

Date: 2017-02-06.00:00:00

According to 6.7.6.5.2 [basic.stc.dynamic.allocation] paragraph 4,

[Note: In particular, a global allocation function is not called to allocate storage for objects with static storage duration (6.7.6.2 [basic.stc.static]), for objects or references with thread storage duration (6.7.6.3 [basic.stc.thread]), for objects of type std::type_info (7.6.1.8 [expr.typeid]), or for an exception object (14.2 [except.throw]). —end note]

The restriction against allocating exception objects on the heap was intended to ensure that heap exhaustion could be reported by throwing an exception, i.e., that obtaining storage for std::bad_alloc could not fail because the heap was full. However, this implicitly relied on the assumption of a single thread and does not scale to large numbers of threads, so the restriction should be lifted and another mechanism found for guaranteeing the ability to throw std::bad_alloc.

History
Date User Action Args
2017-02-06 00:00:00adminsetmessages: + msg5751
2017-02-06 00:00:00adminsetstatus: open -> drafting
2015-01-20 00:00:00admincreate