<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1748</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="1748"></A><H4>1748.
  
Placement new with a null pointer
</H4>
<B>Section: </B>7.6.2.8&#160; [<A href="https://wg21.link/expr.new">expr.new</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD4
 &#160;&#160;&#160;

 <B>Submitter: </B>Marc Glisse
 &#160;&#160;&#160;

 <B>Date: </B>2013-09-11<BR>


<P>[Moved to DR at the November, 2014 meeting.]</P>



<P>According to 7.6.2.8 [<A href="https://wg21.link/expr.new#15">expr.new</A>] paragraph 15,</P>

<BLOCKQUOTE>

[<I>Note:</I> unless an allocation function is declared with a
non-throwing <I>exception-specification</I> (14.5 [<A href="https://wg21.link/except.spec">except.spec</A>]), it
indicates failure to allocate storage by throwing a <TT>std::bad_alloc</TT>
exception (Clause 14 [<A href="https://wg21.link/except">except</A>], 17.6.4.1 [<A href="https://wg21.link/bad.alloc">bad.alloc</A>]);
it returns a non-null pointer otherwise. If the allocation function is
declared with a non-throwing <I>exception-specification</I>, it returns
null to indicate failure to allocate storage and a non-null pointer
otherwise. &#8212;<I>end note</I>] If the allocation function returns null,
initialization shall not be done, the deallocation function shall not be
called, and the value of the <I>new-expression</I> shall be null.

</BLOCKQUOTE>

<P>This wording applies even to the non-replaceable placement forms defined
in 17.6.3.4 [<A href="https://wg21.link/new.delete.placement">new.delete.placement</A>] that simply return the supplied pointer as
the result of the allocation function.  Compilers are thus required to
check for a null pointer and avoid the initialization if one is used.  This
test is unnecessary overhead; it should be the user's responsibility to
ensure that a null pointer is not used in these forms of placement new,
just as for other cases when a pointer is dereferenced.</P>

<P><B>Proposed resolution (February, 2014):</B></P>

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

<BLOCKQUOTE>

[<I>Note:</I> unless an allocation function is declared with a
non-throwing <I>exception-specification</I> (14.5 [<A href="https://wg21.link/except.spec">except.spec</A>]), it
indicates failure to allocate storage by throwing a <TT>std::bad_alloc</TT>
exception (Clause 14 [<A href="https://wg21.link/except">except</A>], 17.6.4.1 [<A href="https://wg21.link/bad.alloc">bad.alloc</A>]);
it returns a non-null pointer otherwise. If the allocation function is
declared with a non-throwing <I>exception-specification</I>, it returns
null to indicate failure to allocate storage and a non-null pointer
otherwise. &#8212;<I>end note</I>] If <INS>the allocation function is a
reserved placement allocation function (17.6.3.4 [<A href="https://wg21.link/new.delete.placement">new.delete.placement</A>]) that
returns null, the behavior is undefined. Otherwise, if</INS> the allocation
function returns null, initialization shall not be done, the deallocation
function shall not be called, and the value of the <I>new-expression</I>
shall be null.

</BLOCKQUOTE>
</P>

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