<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 817</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="817"></A><H4>817.
  
Meaning of <TT>[[final]]</TT> applied to a class definition
</H4>
<B>Section: </B>_N3225_.7.6.4&#160; [<A href="https://wg21.link/dcl.attr.final">dcl.attr.final</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>US
 &#160;&#160;&#160;

 <B>Date: </B>3 March, 2009<BR><BR>


<A href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3086.html#US42">N2800 comment
  US&#160;42<BR></A>

<P>[Voted into WP at March, 2010 meeting.]</P>

<P>According to _N3225_.7.6.4 [<A href="https://wg21.link/dcl.attr.final#1">dcl.attr.final</A>] paragraph 1, the
<TT>[[final]]</TT> attribute applied to a class is just a shorthand
notation for marking each of the class's virtual functions as
<TT>[[final]]</TT>.  This is different from the similar usage in
other languages, where it means that the class so marked cannot be
used as a base class.  This discrepancy is confusing, and the
definition used by the other languages is more useful.</P>

<P><B>Notes from the March, 2009 meeting:</B></P>

<P>The intent of the <TT>[[final]]</TT> attribute is as an aid in
optimization, to avoid virtual function calls when the final
overrider is known. It is possible to use the <TT>[[final]]</TT>
attribute to prevent derivation by marking the destructor as
<TT>[[final]]</TT>; in fact, as most polymorphic classes will, as
a matter of good programming practice, have a virtual destructor,
marking the class as <TT>[[final]]</TT> will have the effect of
preventing derivation.</P>

<P>Nonetheless, the general consensus of the CWG was to change the
meaning of class <TT>[[final]]</TT> to parallel the usage in other
languages.</P>

<P><B>Proposed resolution (October, 2009):</B></P>

<OL>
<LI><P>Change _N3225_.7.6.4 [<A href="https://wg21.link/dcl.attr.final#1">dcl.attr.final</A>] paragraph 1 and add a
new paragraph, as follows:</P></LI>

<BLOCKQUOTE>

<P>The <I>attribute-token</I> <TT>final</TT> specifies <INS>derivation
semantics for a class and</INS> overriding semantics for a virtual
function.  It shall appear at most once in each <I>attribute-list</I>
and no <I>attribute-argument-clause</I> shall be present.  The
attribute applies to class definitions and to virtual member functions
being declared in a class definition. <DEL>If the attribute is specified
for a class definition, it is equivalent to being specified for each
virtual member function of that class, including inherited member
functions.</DEL>
</P>

<P><INS>If some class <TT>B</TT> is marked <TT>final</TT> and a class
<TT>D</TT> is derived from <TT>B</TT> the program is
ill-formed.</INS></P>

</BLOCKQUOTE>

<LI><P>Change the example in _N3225_.7.6.4 [<A href="https://wg21.link/dcl.attr.final#3">dcl.attr.final</A>] paragraph 3
as follows:</P></LI>

<PRE>
  struct B<INS>1</INS> {
    virtual void f [[ final ]] ();
  };

  struct D<INS>1</INS> : B<INS>1</INS> {
    void f();          //<SPAN CLASS="cmnt"> ill-formed</SPAN>
  };

<INS>  struct [[ final ]] B2 {
  };

  struct D2 : B2 {    //<SPAN CLASS="cmnt"> ill-formed</SPAN>
  };</INS>
</PRE>

</OL>

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