<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1202</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="1202"></A><H4>1202.
  
Calling virtual functions during destruction
</H4>
<B>Section: </B>11.9.5&#160; [<A href="https://wg21.link/class.cdtor">class.cdtor</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Bjarne Stroustrup
 &#160;&#160;&#160;

 <B>Date: </B>2010-09-21<BR>


<P>[Voted into the WP at the March, 2011 meeting as part of paper N3262.]</P>



<P>According to 11.9.5 [<A href="https://wg21.link/class.cdtor#4">class.cdtor</A>] paragraph 4,</P>

<BLOCKQUOTE>

Member functions, including virtual functions (11.7.3 [<A href="https://wg21.link/class.virtual">class.virtual</A>]), can be called during construction or destruction
(11.9.3 [<A href="https://wg21.link/class.base.init">class.base.init</A>]).  When a virtual function is called
directly or indirectly from a constructor (including the
<I>mem-initializer</I> or <I>brace-or-equal-initializer</I> for a
non-static data member) or from a destructor, and the object to which
the call applies is the object under construction or destruction, the
function called is the one defined in the constructor or
destructor's own class or in one of its bases, but not a function
overriding it in a class derived from the constructor or
destructor's class, or overriding it in one of the other base
classes of the most derived object (6.8.2 [<A href="https://wg21.link/intro.object">intro.object</A>]).

</BLOCKQUOTE>

<P>This is clear regarding virtual functions called during the
initialization of a class's members, but it does not specifically
address the polymorphic behavior of the class during the destruction
of the members.  Presumably the behavior during destruction should
be the exact inverse of that of the constructor, i.e., the class's
virtual functions should still be called during member
destruction.</P>

<P>In addition, the wording</P>

<BLOCKQUOTE>

If the virtual function call uses an explicit class member access
(7.6.1.5 [<A href="https://wg21.link/expr.ref">expr.ref</A>]) and the object-expression refers to the
object under construction or destruction but its type is neither the
constructor or destructor's own class or one of its bases, the
result of the call is undefined.

</BLOCKQUOTE>

<P>should be clarified that &#8220;refers to the object under
construction&#8221; does not include referring to member
subobjects but only to base or more-derived classes of the class
under construction or destruction.</P>

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