<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 215</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="215"></A><H4>215.
  
Template parameters are not allowed in <I>nested-name-specifier</I>s
</H4>
<B>Section: </B>13.2&#160; [<A href="https://wg21.link/temp.param">temp.param</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Martin von Loewis
 &#160;&#160;&#160;

 <B>Date: </B>13 Mar 2000<BR>


<P>[Voted into WP at April, 2007 meeting.]</P>

<P>According to 13.2 [<A href="https://wg21.link/temp.param#3">temp.param</A>] paragraph 3, the following
fragment is ill-formed:</P>

<PRE>
    template &lt;class T&gt;
    class X{
      friend void T::foo();
    };
</PRE>

<P>In the friend declaration, the <TT>T::</TT> part is a
<I>nested-name-specifier</I> (9.3 [<A href="https://wg21.link/dcl.decl#4">dcl.decl</A>] paragraph 4),
and <TT>T</TT> must be a <I>class-name</I> or a <I>namespace-name</I>
(_N4567_.5.1.1 [<A href="https://wg21.link/expr.prim.general#7">expr.prim.general</A>] paragraph 7). However, according to
13.2 [<A href="https://wg21.link/temp.param#3">temp.param</A>] paragraph 3, it is only a
<I>type-name</I>. The fragment should be well-formed, and
instantiations of the template allowed as long as the actual template
argument is a class which provides a function member <TT>foo</TT>. As
a result of this defect, any usage of template parameters in nested
names is ill-formed, e.g., in the example of 13.8 [<A href="https://wg21.link/temp.res#2">temp.res</A>] paragraph 2.</P>

<P><B>Notes from 04/00 meeting:</B></P>

<P>The discussion at the meeting revealed a self-contradiction in the
current IS in the description of <I>nested-name-specifier</I>s.
According to the grammar in _N4567_.5.1.1 [<A href="https://wg21.link/expr.prim.general#7">expr.prim.general</A>] paragraph 7,
the components of a <I>nested-name-specifier</I> must be either
<I>class-name</I>s or <I>namespace-name</I>s, i.e., the constraint is
syntactic rather than semantic.  On the other hand, 6.5.5 [<A href="https://wg21.link/basic.lookup.qual#1">basic.lookup.qual</A>] paragraph 1 describes a semantic constraint: only
object, function, and enumerator names are ignored in the lookup for
the component, and the program is ill-formed if the lookup finds
anything other than a <I>class-name</I> or <I>namespace-name</I>.  It
was generally agreed that the syntactic constraint should be
eliminated, i.e., that the grammar ought to be changed not to use
<I>class-or-namespace-name</I>.</P>

<P>A related point is the explicit prohibition of use of template
parameters in <I>elaborated-type-specifier</I>s in 9.2.9.5 [<A href="https://wg21.link/dcl.type.elab#2">dcl.type.elab</A>] paragraph 2.  This rule was the result of an
explicit Committee decision and should not be unintentionally voided
by the resolution of this issue.</P>

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

<P>Change _N4567_.5.1.1 [<A href="https://wg21.link/expr.prim.general#7">expr.prim.general</A>] paragraph 7 and
A.5 [<A href="https://wg21.link/gram.expr">gram.expr</A>] from</P>

<UL>
<I>nested-name-specifier</I>:
<UL>
<I>class-or-namespace-name</I> <TT>::</TT> <I>nested-name-specifier<SUB>opt</SUB></I>
</UL>
<UL>
<I>class-or-namespace-name</I> <TT>:: template</TT> <I>nested-name-specifier</I>
</UL>
</UL>
<UL>
<I>class-or-namespace-name</I>:
<UL><I>class-name</I></UL>
<UL><I>namespace-name</I></UL>
</UL>

<P>to</P>

<UL>
<I>nested-name-specifier</I>:
<UL>
<I>type-or-namespace-name</I> <TT>::</TT> <I>nested-name-specifier<SUB>opt</SUB></I>
</UL>
<UL>
<I>type-or-namespace-name</I> <TT>:: template</TT> <I>nested-name-specifier</I>
</UL>
</UL>
<UL>
<I>type-or-namespace-name</I>:
<UL><I>type-name</I></UL>
<UL><I>namespace-name</I></UL>
</UL>

<P>This resolution depends on the resolutions for issues
<A HREF="245.html">245</A> (to change the name lookup rules in
<I>elaborated-type-specifier</I>s to include all <I>type-name</I>s)
and <A HREF="283.html">283</A> (to categorize template
<I>type-parameter</I>s as <I>type-name</I>s).</P>

<P><B>Notes from 10/01 meeting:</B></P>

<P>There was some sentiment for going with simply <I>identifier</I>
in front of the "<TT>::</TT>", and stronger sentiment for going
with something with a more descriptive name if possible.
See also <A HREF="180.html">issue 180</A>.</P>

<P><B>Notes from April 2003 meeting:</B></P>

<P>This was partly resolved by the changes for <A HREF="125.html">issue 125</A>.  However, we also need to add a semantic check in
6.5.5 [<A href="https://wg21.link/basic.lookup.qual">basic.lookup.qual</A>] to allow <TT>T::foo</TT> and we need to
reword the first sentence of 6.5.5 [<A href="https://wg21.link/basic.lookup.qual">basic.lookup.qual</A>].</P>

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

<P>Change 6.5.5 [<A href="https://wg21.link/basic.lookup.qual#1">basic.lookup.qual</A>] paragraph 1 as
follows:</P>

<BLOCKQUOTE>

The name of a class or namespace member can be referred to after
the <TT>::</TT> scope resolution operator (_N4567_.5.1.1 [<A href="https://wg21.link/expr.prim.general">expr.prim.general</A>]) applied to a <I>nested-name-specifier</I> that
nominates its class or namespace. During the lookup for a name
preceding the <TT>::</TT> scope resolution operator, object,
function, and enumerator names are ignored. If the name found
<DEL>is not a <I>class-name</I> (Clause 11 [<A href="https://wg21.link/class">class</A>]) or
<I>namespace-name</I> (9.9.2 [<A href="https://wg21.link/namespace.def">namespace.def</A>])</DEL> <INS>does
not designate a class or namespace</INS>, the program is
ill-formed. [...]

</BLOCKQUOTE>

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

<P>The 10/2004 resolution does not take into account the fact that
template type parameters do not designate class types in the context
of the template definition.  Further drafting is required.
</P>

<P><B>Proposed resolution (April, 2006):</B></P>

<P>Change 6.5.5 [<A href="https://wg21.link/basic.lookup.qual#1">basic.lookup.qual</A>] paragraph 1 as
follows:</P>

<BLOCKQUOTE>

The name of a class or namespace member can be referred to after
the <TT>::</TT> scope resolution operator (_N4567_.5.1.1 [<A href="https://wg21.link/expr.prim.general">expr.prim.general</A>]) applied to a <I>nested-name-specifier</I> that
nominates its class or namespace. During the lookup for a name
preceding the <TT>::</TT> scope resolution operator, object,
function, and enumerator names are ignored. If the name found
<DEL>is not a <I>class-name</I> (Clause 11 [<A href="https://wg21.link/class">class</A>]) or
<I>namespace-name</I> (9.9.2 [<A href="https://wg21.link/namespace.def">namespace.def</A>])</DEL> <INS>does
not designate a namespace or a class or dependent type</INS>, the program is
ill-formed. [...]

</BLOCKQUOTE>

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