<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 374</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="374"></A><H4>374.
  
Can explicit specialization outside namespace use qualified name?
</H4>
<B>Section: </B>9.3.4&#160; [<A href="https://wg21.link/dcl.meaning">dcl.meaning</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Steve Adamczyk
 &#160;&#160;&#160;

 <B>Date: </B>23 August 2002<BR>


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

<P>This case is nonstandard by 9.3.4 [<A href="https://wg21.link/dcl.meaning#1">dcl.meaning</A>] paragraph 1
(there is a requirement that the specialization first be declared within
the namespace before being defined outside of the namespace),
but probably should be allowed:</P>
<PRE>
  namespace NS1 {
    template&lt;class T&gt;
    class CDoor {
    public:
      int mtd() { return 1; }
    };
  }
  template&lt;&gt; int NS1::CDoor&lt;char&gt;::mtd()
  {
    return 0;
  }
</PRE>

<P><B>Notes from October 2002 meeting:</B></P>

<P>There was agreement that we wanted to allow this.</P>

<P><B>Proposed resolution (February, 2010):</B></P>

<OL>
<LI><P>Change 9.3.4 [<A href="https://wg21.link/dcl.meaning">dcl.meaning</A>] as follows:</P></LI>

<BLOCKQUOTE>

...A <I>declarator-id</I> shall not be qualified except for the
definition of a member function (11.4.2 [<A href="https://wg21.link/class.mfct">class.mfct</A>]) or
static data member (11.4.9 [<A href="https://wg21.link/class.static">class.static</A>]) outside of its
class, the definition or explicit instantiation of a function or
variable member of a namespace outside of its namespace, or the
definition of <DEL>a previously declared</DEL> <INS>an</INS>
explicit specialization outside of its namespace, or the
declaration of a friend function that is a member of another
class or namespace (11.8.4 [<A href="https://wg21.link/class.friend">class.friend</A>]). When the
<I>declarator-id</I> is qualified, the declaration shall refer to
a previously declared member of the class or namespace to which
the qualifier refers (or of an inline namespace within that scope
(9.9.2 [<A href="https://wg21.link/namespace.def">namespace.def</A>])) <INS>or to a specialization
thereof</INS>, and the member shall not have been introduced by a
<I>using-declaration</I> in the scope of the class or namespace
nominated by the <I>nested-name-specifier</I> of the
<I>declarator-id</I>.  [<I>Note:</I>...

</BLOCKQUOTE>

<LI><P>Change 13.9.4 [<A href="https://wg21.link/temp.expl.spec">temp.expl.spec</A>] paragraphs 2-4 as follows:</P></LI>

<BLOCKQUOTE>

<P>
<INS>An explicit specialization shall appear in namespace
scope.</INS> An explicit specialization <INS>whose
<I>declarator-id</I> is not qualified</INS> shall be declared in
the nearest enclosing namespace of the template, or, if the
namespace is inline (9.9.2 [<A href="https://wg21.link/namespace.def">namespace.def</A>]), any namespace
from its enclosing namespace set.  Such a declaration may also be
a definition. <DEL>If the declaration is not a definition, the
specialization may be defined later (_N4868_.9.8.2.3 [<A href="https://wg21.link/namespace.memdef">namespace.memdef</A>]).</DEL>
</P>

<P>A declaration of a function template or class template being
explicitly specialized shall <DEL>be in scope at the point
of</DEL> <INS>precede the</INS> declaration of <DEL>an</DEL>
<INS>the</INS> explicit specialization. [<I>Note:</I> a
declaration, but not a definition of the template is required.
&#8212;<I>end note</I>] The definition of a class or class
template shall <DEL>be in scope at the point of</DEL>
<INS>precede the</INS> declaration of an explicit specialization
for a member template of the class or class
template. [<I>Example:</I> ... &#8212;<I>end example</I>]</P>

<P>A member function, a member class or a static data member of a
class template may be explicitly specialized for a class
specialization that is implicitly instantiated; in this case, the
definition of the class template shall <DEL>be in scope at the
point of declaration of</DEL> <INS>preced</INS> the explicit
specialization for the member of the class template.  If such an
explicit specialization for the member of a class template names
an implicitly-declared special member function (
11.4.4 [<A href="https://wg21.link/special">special</A>]), the program is ill-formed.</P>

</BLOCKQUOTE>

</OL>

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