<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 259</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="259"></A><H4>259.
  
Restrictions on explicit specialization and instantiation
</H4>
<B>Section: </B>13.9&#160; [<A href="https://wg21.link/temp.spec">temp.spec</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Matt Austern
 &#160;&#160;&#160;

 <B>Date: </B>2 Nov 2000<BR>


<P>[Moved to DR at 4/02 meeting.]</P>



<P>According to 13.9 [<A href="https://wg21.link/temp.spec#5">temp.spec</A>] paragraph 5,</P>

<BLOCKQUOTE>

No program shall explicitly instantiate any template more than once,
both explicitly instantiate and explicitly specialize a template, or
specialize a template more than once for a given set of
<I>template-argument</I>s.

</BLOCKQUOTE>

<P>This rule has an impact on library issue 120.  Library authors
would like to have the freedom to specialize (or not) various
library functions without having to document their choices, while
users need the flexibility to explicitly instantiate library
functions in certain translation units.</P>

<P>If this rule could be slightly weakened, it would reduce the need
for constraining either the library author or the programmer.  For
instance, the rule might be recast to say that if a specialization is
followed by an explicit instantiation in the same translation unit,
the explicit instantiation is ignored.  A specialization and an
explicit instantiation of the same template in two different
translation units would still be an error, no diagnostic required.</P>

<P><B>Proposed resolution (04/01):</B></P>

<OL>
<LI>
<P>Replace the first sentence of 13.9 [<A href="https://wg21.link/temp.spec#5">temp.spec</A>] paragraph 5,
</P>

<BLOCKQUOTE>

No program shall explicitly instantiate any template more
than once, both explicitly instantiate and explicitly
specialize a template, or specialize a template more than
once for a given set of <I>template-argument</I>s.

</BLOCKQUOTE>

<P>by</P>

<BLOCKQUOTE>

For a given template and a given set of <I>template-argument</I>s,

<UL>
<LI>an explicit instantiation shall appear at most once in a
program,</LI>

<LI>an explicit specialization shall be defined at most once
according to 6.3 [<A href="https://wg21.link/basic.def.odr">basic.def.odr</A>] in a program, and</LI>

<LI>both an explicit instantiation and a declaration of an
explicit specialization shall not appear in a program unless
the explicit instantiation follows a declaration of the explicit
specialization.</LI>

</UL>

</BLOCKQUOTE>
</LI>

<LI>
<P>Replace 13.9.3 [<A href="https://wg21.link/temp.explicit#4">temp.explicit</A>] paragraph 4,</P>

<BLOCKQUOTE>

The definition of a non-exported function template, a non-exported
member function template, or a non-exported member function or
static data member of a class template shall be present in every
translation unit in which it is explicitly instantiated.

</BLOCKQUOTE>

<P>by</P>

<BLOCKQUOTE>

For a given set of template parameters, if an explicit
instantiation of a template appears after a declaration of
an explicit specialization for that template, the explicit
instantiation has no effect.  Otherwise, the definition of a
non-exported function template, a non-exported member
function template, or a non-exported member function or static
data member of a class template shall be present in every
translation unit in which it is explicitly instantiated.

</BLOCKQUOTE>
</LI>

</OL>

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