<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 382</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="382"></A><H4>382.
  
Allow <TT>typename</TT> outside of templates
</H4>
<B>Section: </B>13.8&#160; [<A href="https://wg21.link/temp.res">temp.res</A>]
 &#160;&#160;&#160;

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

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

 <B>Date: </B>8 Nov 2002<BR>


<P>[Voted into WP at October 2005 meeting.]</P>

<P>P. J. Plauger, among others, has noted that <TT>typename</TT> is hard
to use, because in a given context it's either required or forbidden,
and it's often hard to tell which.
It would make life easier for programmers if <TT>typename</TT>
could be allowed in places where it is not required, e.g., outside
of templates.</P>

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

<P>There was unanimity on relaxing this requirement on typename.
The question was how much to relax it.  Everyone agreed on allowing
it on all qualified names, which is an easy fix (no syntax change
required).  But should it be allowed other places?  P.J. Plauger
said he'd like to see it allowed anywhere a type name is allowed,
and that it could actually be a decades-late assist for the infamous
"the ice is thin here" typedef problem noted in K&amp;R I.</P>

<P><B>Proposed resolution (April 2003):</B></P>

<P>Replace the text at the start of 13.8 [<A href="https://wg21.link/temp.res#3">temp.res</A>] paragraph 3:</P>

<BLOCKQUOTE>
A <I>qualified-id</I> that refers to a type and in which
the <I>nested-name-specifier</I>
depends on a <I>template-parameter</I> (13.8.3 [<A href="https://wg21.link/temp.dep">temp.dep</A>])
shall be prefixed by the keyword
<TT>typename</TT> to indicate that
the <I>qualified-id</I> denotes a type, forming an
<I>elaborated-type-specifier</I> (9.2.9.5 [<A href="https://wg21.link/dcl.type.elab">dcl.type.elab</A>]).
</BLOCKQUOTE>

<P>With:</P>

<BLOCKQUOTE>
The keyword <TT>typename</TT> can only be applied to a <I>qualified-id</I>. A
<I>qualified-id</I> that refers to a type and in which
the <I>nested-name-specifier</I>
depends on a <I>template-parameter</I> (13.8.3 [<A href="https://wg21.link/temp.dep">temp.dep</A>])
shall be prefixed by the keyword
<TT>typename</TT> to indicate that the <I>qualified-id</I>
denotes a type, forming
an <I>elaborated-type-specifier</I> (9.2.9.5 [<A href="https://wg21.link/dcl.type.elab">dcl.type.elab</A>]).
If a <I>qualified-id</I> which
has been prefixed by the keyword <TT>typename</TT> does not
denote a type the program is ill-formed.
[ <I>Note:</I> The keyword is only required on a <I>qualified-id</I> within a
template declaration or definition in which the
<I>nested-name-specifier</I> depends on a <I>template-parameter</I>. ]
</BLOCKQUOTE>

<P>Remove 13.8 [<A href="https://wg21.link/temp.res#5">temp.res</A>] paragraph 5:</P>

<BLOCKQUOTE>
The keyword <TT>typename</TT> shall only be used in template
declarations and definitions, including in the return type of a function template or
member function template, in the return type for the definition of a member function
of a class template or of a class nested within a class template, and in the
<I>type-specifier</I> for the definition of a static member of a class template or
of a class nested within a class template. The keyword <TT>typename</TT> shall be
applied only to qualified names, but those names need not be dependent. The keyword
<TT>typename</TT> shall be used only in contexts in which dependent names
can be used. This includes template declarations and definitions but excludes explicit
specialization declarations and explicit instantiation declarations. The keyword
<TT>typename</TT>
is not permitted in a <I>base-specifier</I> or in a <I>mem-initializer</I>; in these
contexts a <I>qualified-id</I> that depends on a <I>template-parameter</I> (temp.dep) is
implicitly assumed to be a type name.
</BLOCKQUOTE>

<P>
<B>Note:</B> the claim here that a qualified name preceded by
<TT>typename</TT> forms an elaborated type specifier conflicts with
the changes made in <A HREF="254.html">issue 254</A> (see
N1376=02-0034), which introduces <I>typename-specifier</I>.</P>

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

<P>We considered whether <TT>typename</TT> should be allowed in more
places, and decided we only wanted to allow it in qualified
names (for now at least).</P>

<P>
<A HREF="254.html">Core issue 254</A> changed
<I>elaborated-type-specifier</I> to <I>typename-specifier</I>.
It also changed 13.8 [<A href="https://wg21.link/temp.res#5">temp.res</A>] paragraph 5, which
this proposed resolution deletes.  </P>

<P>See also <A HREF="468.html">issue 468</A>.</P>

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

<OL>

<LI>
<P>Change 13.8 [<A href="https://wg21.link/temp.res#3">temp.res</A>] paragraph 3 as
follows:</P>

<BLOCKQUOTE>

<DEL>A</DEL> <INS>When a</INS> <I>qualified-id</I> <DEL>that refers to a
type and</DEL> in which the <I>nested-name-specifier</I> depends on a
<I>template-parameter</I> (13.8.3 [<A href="https://wg21.link/temp.dep">temp.dep</A>]) <INS>is
intended to refer to a type, it</INS> shall be prefixed by the
keyword <TT>typename</TT> <DEL>to indicate that the qualified-id
denotes a type</DEL>, forming a <I>typename-specifier</I>. <INS>If
the <I>qualified-id</I> in a <I>typename-specifier</I> does not
denote a type, the program is ill-formed.</INS>

</BLOCKQUOTE>

</LI>

<LI>
<P>Change 13.8 [<A href="https://wg21.link/temp.res#5">temp.res</A>] paragraph 5 as
follows:</P>

<BLOCKQUOTE>

<DEL>The keyword <TT>typename</TT> shall only be used in template
declarations and definitions, including in the return type of a
function template or member function template, in the return type
for the definition of a member function of a class template or of
a class nested within a class template, and in the
<I>type-specifier</I> for the definition of a static member of a
class template or of a class nested within a class template. The
keyword <TT>typename</TT> shall be applied only to qualified
names, but those names need not be dependent. The keyword
<TT>typename</TT> shall be used only in contexts in which
dependent names can be used. This includes template declarations
and definitions but excludes explicit specialization declarations
and explicit instantiation declarations.</DEL> A qualified name
used as the name in a <I>mem-initializer-id</I>, a
<I>base-specifier</I>, or an <I>elaborated-type-specifier</I> is
implicitly assumed to name a type, without the use of the
<TT>typename</TT> keyword. [<I>Note:</I> the <TT>typename</TT>
keyword is not permitted by the syntax of these
constructs. &#8212;<I>end note</I>]

</BLOCKQUOTE>

</LI>

</OL>

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