<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2102</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="2102"></A><H4>2102.
  
Constructor checking in <I>new-expression</I>
</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>CD7
 &#160;&#160;&#160;

 <B>Submitter: </B>Richard Smith
 &#160;&#160;&#160;

 <B>Date: </B>2015-03-16<BR>


<P>[Accepted as a DR at the November, 2023 meeting.]</P>



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

<BLOCKQUOTE>

If the <I>new-expression</I> creates an object or an array
of objects of class type, access and ambiguity control are
done for the allocation function, the deallocation function
(11.4.11 [<A href="https://wg21.link/class.free">class.free</A>]), and the constructor
(11.4.5 [<A href="https://wg21.link/class.ctor">class.ctor</A>]).

</BLOCKQUOTE>

<P>The mention of &#8220;the constructor&#8221; here is
strange.  For the &#8220;object of class type&#8221; case,
access and ambiguity control are done when we perform
initialization in paragraph 17, and we might not be calling a
constructor anyway (for aggregate initialization). This
seems wrong.</P>

<P>For the &#8220;array of objects of class type&#8221;
case, it makes slightly more sense (we need to check the
trailing array elements can be default-initialized) but
again (a) we aren't necessarily using a constructor, (b) we
should say <I>which</I> constructor &#8212; and we may need
overload resolution to find it, and (c) shouldn't this be
part of initialization, so we can distinguish between the
cases where we should copy-initialize from <TT>{}</TT> and
the cases where we should default-initialize?</P>

<P><B>Additional notes (May, 2023):</B></P>

<P>It is unclear whether default-initialization is required to be
well-formed even for an array with no elements.</P>

<P><B>Proposed resolution (approved by CWG 2023-06-16):</B></P>

<OL>
<LI>
<P>Insert a new paragraph before 7.6.2.8 [<A href="https://wg21.link/expr.new#9">expr.new</A>] paragraph 9:</P>

<BLOCKQUOTE>

<P class="ins">If the allocated type is an array,
the <I>new-initializer</I> is a <I>braced-init-list</I>, and
the <I>expression</I> is potentially-evaluated and not a core constant
expression, the semantic constraints of copy-initializing a
hypothetical element of the array from an empty initializer list are
checked (9.5.5 [<A href="https://wg21.link/dcl.init.list">dcl.init.list</A>]). [ Note: The array can contain
more elements than there are elements in the <I>braced-init-list</I>,
requiring initialization of the remainder of the array elements from
an empty initializer list. -- end note ]</P>

<P>Objects created by a new-expression have dynamic storage duration
(6.8.6.5 [<A href="https://wg21.link/basic.stc.dynamic">basic.stc.dynamic</A>]). ...</P>

</BLOCKQUOTE>

</LI>

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

<BLOCKQUOTE>

<DEL>If the <I>new-expression</I> creates an object or an array of objects
of class type, access and ambiguity control are done for the
allocation function, the deallocation function
(6.8.6.5.3 [<A href="https://wg21.link/basic.stc.dynamic.deallocation">basic.stc.dynamic.deallocation</A>]), and the constructor
(11.4.5 [<A href="https://wg21.link/class.ctor">class.ctor</A>]) selected for the initialization (if
any).</DEL> If the <I>new-expression</I> creates an array of objects of
class type, the destructor is potentially invoked
(11.4.7 [<A href="https://wg21.link/class.dtor">class.dtor</A>]).

</BLOCKQUOTE>
</LI>

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

<BLOCKQUOTE>

A declaration of a placement deallocation function matches the
declaration of a placement allocation function if it has the same
number of parameters and, after parameter transformations
(9.3.4.6 [<A href="https://wg21.link/dcl.fct">dcl.fct</A>]), all parameter types except the first
are identical. If the lookup finds a single matching deallocation
function, that function will be called; otherwise, no deallocation
function will be called. If the lookup finds a usual deallocation
function and that function, considered as a placement deallocation
function, would have been selected as a match for the allocation
function, the program is ill-formed. For a non-placement allocation
function, the normal deallocation function lookup is used to find the
matching deallocation function (7.6.2.9 [<A href="https://wg21.link/expr.delete">expr.delete</A>]).
<INS>In any case, the matching deallocation function (if any) shall be
non-deleted and accessible from the point where
the <I>new-expression</I> appears.</INS>

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 9.5.1 [<A href="https://wg21.link/dcl.init.general#7">dcl.init.general</A>] paragraph 7 as follows:</P>

<BLOCKQUOTE>

To <I>default-initialize</I> an object of type T means:
<UL>
<LI>...</LI>
<LI>If T is an array type, <INS>the semantic constraints of
default-initializing a hypothetical element shall be met and</INS>
each element is default-initialized.</LI>
<LI>...</LI>
</UL>

</BLOCKQUOTE>
</LI>

<LI>
<P>Change in 9.5.1 [<A href="https://wg21.link/dcl.init.general#9">dcl.init.general</A>] paragraph 9 as follows:</P>

<BLOCKQUOTE>

To <I>value-initialize</I> an object of type T means:

<UL>
<LI>
<DEL>if</DEL> <INS>If</INS> T is a
(possibly cv-qualified) class type (Clause 11 [<A href="https://wg21.link/class">class</A>]),
then
<UL>
<LI>if T has either no default constructor
(11.4.5.2 [<A href="https://wg21.link/class.default.ctor">class.default.ctor</A>]) or a default constructor that is
user-provided or deleted, then the object is default-initialized;
</LI>
<LI>
otherwise, the object is zero-initialized and the semantic constraints
for default-initialization are checked, and if T has a non-trivial
default constructor, the object is
default-initialized<DEL>;</DEL><INS>.</INS>
</LI>
</UL>
</LI>

<LI>
<DEL>if</DEL> <INS>If</INS> T is an array type, <INS>the semantic
constraints of value-initializing a hypothetical element shall be met
and</INS> each element is value-initialized<DEL>;</DEL><INS>.</INS>
</LI>

<LI>
<DEL>otherwise</DEL><INS>Otherwise</INS>, the object is
zero-initialized.</LI>

</UL>

</BLOCKQUOTE>
</LI>



</OL>

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