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

2024-03-20


938. Initializer lists and array new

Section: 9.4.2  [dcl.init.aggr]     Status: C++11     Submitter: Alisdair Meredith     Date: 12 July, 2009

[Voted into the WP at the March, 2011 meeting.]

9.4.2 [dcl.init.aggr] paragraph 4 says,

An initializer-list is ill-formed if the number of initializer-clauses exceeds the number of members or elements to initialize.

However, in a new-expression, the number of elements to be initialized is potentially unknown at compile time. How should an overly-long initializer-list in a new-expression be treated?

Notes from the August, 2010 meeting:

The consensus of the CWG was that this case should throw an exception at runtime.

Proposed resolution (January, 2011):

Change 7.6.2.8 [expr.new] paragraph 7 as follows:

When the value of the expression in a noptr-new-declarator is zero, the allocation function is called to allocate an array with no elements. If the value of that expression is less than zero or such that the size of the allocated object would exceed the implementation-defined limit, or if the new-initializer is a braced-init-list for which the number of initializer-clauses exceeds the number of elements to initialize, no storage is obtained and the new-expression terminates by throwing an exception of a type that would match a handler (14.4 [except.handle]) of type std::bad_array_new_length (17.6.4.2 [new.badlength]).