<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2490</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="2490"></A><H4>2490.
  
Restrictions on destruction in constant expressions
</H4>
<B>Section: </B>7.7&#160; [<A href="https://wg21.link/expr.const">expr.const</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Jiang An
 &#160;&#160;&#160;

 <B>Date: </B>2021-05-04<BR>


<P>[Accepted as a DR at the October, 2021 meeting.]</P>

<P>According to 7.7 [<A href="https://wg21.link/expr.const#6">expr.const</A>] paragraph 6,</P>

<BLOCKQUOTE>

<P>For the purposes of determining whether an
expression <I>E</I> is a core constant expression, the
evaluation of a call to a member function of
<TT>std::allocator&lt;T&gt;</TT> as defined in
20.2.10.2 [<A href="https://wg21.link/allocator.members">allocator.members</A>], where <TT>T</TT> is a
literal type, does not disqualify <I>E</I> from being a core
constant expression, even if the actual evaluation of such a
call would otherwise fail the requirements for a core
constant expression. Similarly, the evaluation of a call to
<TT>std::destroy_at</TT>, <TT>std::ranges::destroy_at</TT>,
<TT>std::construct_at</TT>,
or <TT>std::ranges::construct_at</TT> does not
disqualify <TT>E</TT> from being a core constant expression
unless:</P>

<UL>
<LI><P>for a call to <TT>std::construct_at</TT> or
<TT>std::ranges::construct_at</TT>, the first argument, of
type <TT>T*</TT>, does not point to storage allocated with
<TT>std::allocator&lt;T&gt;</TT> or to an object whose
lifetime began within the evaluation of <I>E</I>, or the
evaluation of the underlying constructor call
disqualifies <I>E</I> from being a core constant expression,
or</P></LI>

<LI><P>for a call to <TT>std::destroy_at</TT> or
<TT>std::ranges::destroy_at</TT>, the first argument, of
type <TT>T*</TT>, does not point to storage allocated with
<TT>std::allocator&lt;T&gt;</TT> or to an object whose
lifetime began within the evaluation of <I>E</I>, or the
evaluation of the underlying destructor call
disqualifies <I>E</I> from being a core constant
expression.</P></LI>

</UL>

</BLOCKQUOTE>

<P>There are, however, no specific restrictions in
7.7 [<A href="https://wg21.link/expr.const">expr.const</A>] regarding destructor or
pseudo-destructor calls. In particular, a constexpr
destructor can be called for any object, regardless of
how it was constructed or the start of its lifetime,
and similarly for pseudo-destructor calls. This seems
inconsistent.</P>

<P>If those restrictions are added, would the specific
restrictions on library destruction facilities still be
needed?</P>

<P><B>Notes from the August, 2021 teleconference:</B></P>

<P>CWG agreed that since trivial destructors and
pseudo-destructors are now considered to end the lifetime of
the object for which they are called, they should be
prohibited from being invoked for a runtime object in a
constant expression.</P>

<P><B>Proposed resolution (August, 2021):</B></P>

<OL>
<LI><P>Change 7.7 [<A href="https://wg21.link/expr.const#5">expr.const</A>] paragraph 5 as follows:</P></LI>

<BLOCKQUOTE>

<P>An expression <I>E</I> is a <I>core constant expression</I>
unless the evaluation of <I>E</I>, following the rules of the
abstract machine (6.10.1 [<A href="https://wg21.link/intro.execution">intro.execution</A>]), would
evaluate one of the following:</P>

<UL>
<LI><P>...</P></LI>

<LI><P>a modification of an object
(7.6.19 [<A href="https://wg21.link/expr.assign">expr.assign</A>], 7.6.1.6 [<A href="https://wg21.link/expr.post.incr">expr.post.incr</A>],
7.6.2.3 [<A href="https://wg21.link/expr.pre.incr">expr.pre.incr</A>]) unless it is applied to a
non-volatile lvalue of literal type that refers to a
non-volatile object whose lifetime began within the
evaluation of <I>E</I>;</P></LI>

<LI><P><INS>an invocation of a destructor
(11.4.7 [<A href="https://wg21.link/class.dtor">class.dtor</A>]) or a function call whose
<I>postfix-expression</I> names a pseudo-destructor
(7.6.1.3 [<A href="https://wg21.link/expr.call">expr.call</A>]), in either case for an
object whose lifetime did not begin within the evaluation
of <I>E</I>;</INS></P></LI>

<LI><P>a <I>new-expression</I> (7.6.2.8 [<A href="https://wg21.link/expr.new">expr.new</A>]),
unless...</P></LI>

</UL>

</BLOCKQUOTE>

<LI><P>Change 7.7 [<A href="https://wg21.link/expr.const#6">expr.const</A>] paragraph 6 as follows,
merging the single remaining bulleted item into the running text
of the paragraph:</P></LI>

<BLOCKQUOTE>

<P>For the purposes of determining whether an
expression <I>E</I> is a core constant expression, the
evaluation of a call to a member function of
<TT>std::allocator&lt;T&gt;</TT> as defined in
20.2.10.2 [<A href="https://wg21.link/allocator.members">allocator.members</A>], where <TT>T</TT> is a
literal type, does not disqualify <I>E</I> from being a core
constant expression, even if the actual evaluation of such a
call would otherwise fail the requirements for a core
constant expression. Similarly, the evaluation of a call to
<DEL><TT>std::destroy_at</TT>, <TT>std::ranges::destroy_at</TT>,</DEL>
<TT>std::construct_at</TT><DEL>,</DEL>
or <TT>std::ranges::construct_at</TT> does not
disqualify <I>E</I> from being a core constant expression
unless<DEL>:</DEL>
</P>

<UL>
<LI><P>
<DEL>for a call to <TT>std::construct_at</TT> or
<TT>std::ranges::construct_at</TT>,</DEL> the first
argument, of type <TT>T*</TT>, does not point to storage
allocated with
<TT>std::allocator&lt;T&gt;</TT> or to an object whose
lifetime began within the evaluation of <I>E</I>, or the
evaluation of the underlying constructor call
disqualifies <I>E</I> from being a core constant
expression<DEL>, or</DEL>
</P></LI>

<LI><P>
<DEL>for a call to <TT>std::destroy_at</TT> or
<TT>std::ranges::destroy_at</TT>, the first argument, of
type <TT>T*</TT>, does not point to storage allocated with
<TT>std::allocator&lt;T&gt;</TT> or to an object whose
lifetime began within the evaluation of <I>E</I>, or the
evaluation of the underlying destructor call
disqualifies <I>E</I> from being a core constant
expression</DEL>.</P></LI>

</UL>

</BLOCKQUOTE>

</OL>

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