<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 938</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="938"></A><H4>938.
  
Initializer lists and array new
</H4>
<B>Section: </B>9.5.2&#160; [<A href="https://wg21.link/dcl.init.aggr">dcl.init.aggr</A>]
 &#160;&#160;&#160;

 <B>Status: </B>C++11
 &#160;&#160;&#160;

 <B>Submitter: </B>Alisdair Meredith
 &#160;&#160;&#160;

 <B>Date: </B>12 July, 2009<BR>


<P>[Voted into the WP at the March, 2011 meeting.]</P>



<P>9.5.2 [<A href="https://wg21.link/dcl.init.aggr#4">dcl.init.aggr</A>] paragraph 4 says,</P>

<BLOCKQUOTE>

An <I>initializer-list</I> is ill-formed if the number of
<I>initializer-clause</I>s exceeds the number of members or elements
to initialize.

</BLOCKQUOTE>

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

<P><B>Notes from the August, 2010 meeting:</B></P>

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

<P><B>Proposed resolution (January, 2011):</B></P>

<P>Change 7.6.2.8 [<A href="https://wg21.link/expr.new#7">expr.new</A>] paragraph 7 as follows:</P>

<BLOCKQUOTE>

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

</BLOCKQUOTE>

<BR><BR>
</BODY>
</HTML>
