<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1318</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="1318"></A><H4>1318.
  
Syntactic ambiguities with <TT>final</TT>
</H4>
<B>Section: </B>Clause 11&#160; [<A href="https://wg21.link/class">class</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Johannes Schaub
 &#160;&#160;&#160;

 <B>Date: </B>2011-05-14<BR>


<P>[Moved to DR at the April, 2013 meeting.]</P>



<P>The ambiguity in an example like</P>

<PRE>
  struct A final { };
</PRE>

<P>is resolved by 5.11 [<A href="https://wg21.link/lex.name#2">lex.name</A>] paragraph 2 to be the
declaration of a variable named <TT>final</TT>:</P>

<BLOCKQUOTE>

any ambiguity as to whether a given <I>identifier</I> has a special
meaning is resolved to interpret the token as a regular
<I>identifier</I>.

</BLOCKQUOTE>

<P>Similarly, in an example like</P>

<PRE>
  struct C { constexpr operator int() { return 5; } };
  struct A {
   struct B final : C{};
  };
</PRE>

<P>
<TT>final</TT> is taken as the name of a bit-field member rather than
as the name of a nested class.</P>

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

<OL>
<LI><P>Change 5.11 [<A href="https://wg21.link/lex.name#2">lex.name</A>] paragraph 2 as follows:</P></LI>

<BLOCKQUOTE>

The identifiers in Table 3 have a special meaning when appearing in a
certain context.  When referred to in the grammar, these identifiers
are used explicitly rather than using the <I>identifier</I> grammar
production. <INS>Unless otherwise specified,</INS> any ambiguity as to
whether a given identifier has a special meaning is resolved to
interpret the token as a regular
<I>identifier</I>.

</BLOCKQUOTE>

<LI><P>Change Clause 11 [<A href="https://wg21.link/class#3">class</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

<P>If a class is marked with the <I>class-virt-specifier</I>
<TT>final</TT> and it appears as a <I>base-type-specifier</I> in a
<I>base-clause</I> (11.7 [<A href="https://wg21.link/class.derived">class.derived</A>]), the program is
ill-formed. <INS>Whenever a <I>class-key</I> is followed by a
<I>class-head-name</I>, the <I>identifier</I> <TT>final</TT>, and a
colon or left brace, <TT>final</TT> is interpreted as a
<I>class-virt-specifier</I>. [<I>Example:</I></INS>
</P>

<PRE>
<INS>  struct A;
  struct A final {};      //<SPAN CLASS="cmnt"> OK: definition of </SPAN>struct A<SPAN CLASS="cmnt">,</SPAN>
                          //<SPAN CLASS="cmnt"> not value-initialization of variable </SPAN>final

  struct X {
   struct C { constexpr operator int() { return 5; } };
   struct B final : C{};  //<SPAN CLASS="cmnt"> OK: definition of nested class </SPAN>B<SPAN CLASS="cmnt">,</SPAN>
                          //<SPAN CLASS="cmnt"> not declaration of a bit-field member </SPAN>final
  };</INS>
</PRE>

<P><INS>&#8212;<I>end example</I>]</INS></P>

</BLOCKQUOTE>

</OL>

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