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


2073. Allocating memory for exception objects

Section:  []     Status: drafting     Submitter: Jonathan Wakely     Date: 2015-01-20

According to [] paragraph 4,

[Note: In particular, a global allocation function is not called to allocate storage for objects with static storage duration ( []), for objects or references with thread storage duration ( []), for objects of type std::type_info ( [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.

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.