<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 276</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="276"></A><H4>276.
  
Order of destruction of parameters and temporaries
</H4>
<B>Section: </B>8.8&#160; [<A href="https://wg21.link/stmt.jump">stmt.jump</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>James Kanze
 &#160;&#160;&#160;

 <B>Date: </B>28 Mar 2001<BR>


<P>[Voted into the WP at the June, 2008 meeting.]</P>

<P>According to 8.8 [<A href="https://wg21.link/stmt.jump#2">stmt.jump</A>] paragraph 2,</P>

<BLOCKQUOTE>

On exit from a scope (however accomplished), destructors (11.4.7 [<A href="https://wg21.link/class.dtor">class.dtor</A>]) are called for all constructed objects with automatic
storage duration (6.8.6.4 [<A href="https://wg21.link/basic.stc.auto">basic.stc.auto</A>]) (named objects or
temporaries) that are declared in that scope, in the reverse order of
their declaration.

</BLOCKQUOTE>

<P>This wording is problematic for temporaries and for parameters.
First, temporaries are not "declared," so this requirement does not
apply to them, in spite of the assertion in the quoted text that it
does.</P>

<P>Second, although the parameters of a function are <I>declared</I>
in the called function, they are constructed and destroyed in the
calling context, and the order of evaluation of the arguments is
unspecified (cf 7.6.1.3 [<A href="https://wg21.link/expr.call">expr.call</A>] paragraphs 4 and 8).
The order of destruction of the parameters might, therefore, be
different from the reverse order of their declaration.</P>

<P><B>Notes from 04/01 meeting:</B></P>

<P>Any resolution of this issue should be careful not to introduce
requirements that are redundant or in conflict with those of other
parts of the IS.  This is especially true in light of the pending
issues with respect to the destruction of temporaries (see issues
<A HREF="86.html">86</A>, <A HREF="124.html">124</A>,
<A HREF="199.html">199</A>, and <A HREF="201.html">201</A>).
If possible, the wording of a resolution should simply reference
the relevant sections.</P>

<P>It was also noted that the temporary for a return value is
also destroyed "out of order."  </P>

<P>Note that <A HREF="378.html">issue 378</A> picks a nit
with the wording of this same paragraph.</P>

<P><B>Proposed Resolution (November, 2006):</B></P>

<P>Change 8.8 [<A href="https://wg21.link/stmt.jump#2">stmt.jump</A>] paragraph 2 as follows:</P>

<BLOCKQUOTE>

On exit from a scope (however accomplished), <DEL>destructors
(11.4.7 [<A href="https://wg21.link/class.dtor">class.dtor</A>]) are called for all constructed objects
with automatic storage duration (6.8.6.4 [<A href="https://wg21.link/basic.stc.auto">basic.stc.auto</A>]) (named
objects or temporaries) that are declared in that scope, in the
reverse order of their declaration.</DEL> <INS>variables with automatic
storage duration (6.8.6.4 [<A href="https://wg21.link/basic.stc.auto">basic.stc.auto</A>]) that have been
constructed in that scope are destroyed in the reverse order of their
construction. [<I>Note:</I> For temporaries, see 6.8.7 [<A href="https://wg21.link/class.temporary">class.temporary</A>].
&#8212;<I>end note</I>]</INS> Transfer out of a loop...

</BLOCKQUOTE>

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