<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1484</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="1484"></A><H4>1484.
  
Unused local classes of function templates
</H4>
<B>Section: </B>13.9.2&#160; [<A href="https://wg21.link/temp.inst">temp.inst</A>]
 &#160;&#160;&#160;

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

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

 <B>Date: </B>2012-03-25<BR>


<P>[Moved to DR at the November, 2014 meeting.]</P>



<P>Do local classes of function templates get the same treatment as
member classes of class templates? In particular, is their definition
only instantiated when they are required? For example,</P>

<PRE>
  template&lt;typename T&gt; void f() {
    struct B {
      T t;
    };
  }

  int main() {
    f&lt;void&gt;();
  }
</PRE>

<P>Implementations vary on this question.</P>

<P>(This question is superficially similar to the one in
<A HREF="1253.html">issue 1253</A>. However, the entities in
view in that issue can be named and defined outside the containing
template and thus can be explicitly specialized, none of which is
true for local classes of function templates.)</P>

<P>It should also be noted that the resolution of this issue should
apply as well to local enumeration types.</P>

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

<P>Change 13.9.2 [<A href="https://wg21.link/temp.inst#1">temp.inst</A>] paragraph 1 as follows:</P>

<BLOCKQUOTE>

Unless a class template specialization has been explicitly
instantiated (13.9.3 [<A href="https://wg21.link/temp.explicit">temp.explicit</A>]) or explicitly specialized
(13.9.4 [<A href="https://wg21.link/temp.expl.spec">temp.expl.spec</A>]), the class template specialization is
implicitly instantiated when the specialization is referenced in a
context that requires a completely-defined object type or when the
completeness of the class type affects the semantics of the program.
<INS>[<I>Note:</I> Within a template declaration, a local class or
enumeration and the members of a local class are never considered to
be entities that can be separately instantiated (this includes their
default arguments, <I>exception-specification</I>s, and non-static data
member initializers, if any). As a result, the dependent names are
looked up, the semantic constraints are checked, and any templates
used are instantiated as part of the instantiation of the entity
within which the local class or enumeration is declared. &#8212;<I>end
note</I>]</INS> The implicit instantiation of a class template
specialization...

</BLOCKQUOTE>

<P><B>Notes from the April, 2013 meeting:</B></P>

<P>The proposed resolution interacts with N3649 (generic lambdas),
adopted at this meeting, and this issue has returned to "review"
status to allow any necessary changes to be made.</P>

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