<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2392</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="2392"></A><H4>2392.
  
<I>new-expression</I> size check and constant evaluation
</H4>
<B>Section: </B>7.7&#160; [<A href="https://wg21.link/expr.const">expr.const</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Tam S. B
 &#160;&#160;&#160;

 <B>Date: </B>2018-12-05<BR>


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

<P>According to 7.6.2.8 [<A href="https://wg21.link/expr.new#8">expr.new</A>] paragraph 8, if the
<I>expression</I> in a <I>noptr-new-declarator</I> is a core constant
expression, the program is ill-formed if the <I>expression</I> is
erroneous, e.g., negative. However, consider the following example:</P>

<PRE>
  template&lt;class T = void&gt; constexpr int f() { T t; return 1; }
  using _ = decltype(new int[f()]);
</PRE>

<P>
<TT>f()</TT> is a core constant expression, so it must be evaluated to
determine its value. However, because the expression appears in an
unevaluated operand, it is not &#8220;potentially constant evaluated&#8221;
and thus <TT>f</TT> is not &#8220;needed for constant evaluation&#8221;, so
the template is not instantiated (13.9.2 [<A href="https://wg21.link/temp.inst#7">temp.inst</A>] paragraph 7).
There is implementation divergence on the handling of this example.</P>

<P><B>CWG telecon 2022-09-09:</B></P>

<P>The example should be well-formed, because <TT>f</TT> is not
instantiated.</P>

<P>A similar situation arises for narrowing conversions, except that
in the latter case, determining the value at compile-time empowers to
allow additional cases, whereas the <I>new-expression</I> case uses a
compile-time value to prohibit additional cases.</P>

<P><B>Proposed resolution (approved by CWG 2022-09-23):</B></P>

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

<BLOCKQUOTE>

If the expression is erroneous after converting to <TT>std::size_t</TT>:
<UL>

<LI>if the expression is a <INS>potentially-evaluated</INS> core
constant expression, the program is ill-formed;</LI>

<LI>otherwise, an allocation function is not called; instead...</LI>

</UL>

</BLOCKQUOTE>

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