<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 625</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="625"></A><H4>625.
  
Use of <TT>auto</TT> as a <I>template-argument</I>
</H4>
<B>Section: </B>9.2.9.7&#160; [<A href="https://wg21.link/dcl.spec.auto">dcl.spec.auto</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>John Spicer
 &#160;&#160;&#160;

 <B>Date: </B>9 March 2007<BR>


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

<P>The <TT>auto</TT> specifier can be used only in certain contexts,
as specified in 9.2.9.7 [<A href="https://wg21.link/dcl.spec.auto">dcl.spec.auto</A>] paragraphs 2-3:</P>

<BLOCKQUOTE>

<P>Otherwise (<TT>auto</TT> appearing with no type specifiers other than
<I>cv-qualifier</I>s), the <TT>auto</TT> <I>type-specifier</I>
signifies that the type of an object being declared shall be deduced
from its initializer. The name of the object being declared shall not
appear in the initializer expression.</P>

<P>This use of <TT>auto</TT> is allowed when declaring objects in a
block (8.4 [<A href="https://wg21.link/stmt.block">stmt.block</A>]), in namespace scope (6.4.6 [<A href="https://wg21.link/basic.scope.namespace">basic.scope.namespace</A>]), and in a <I>for-init-statement</I> (8.6.4 [<A href="https://wg21.link/stmt.for">stmt.for</A>]).  The <I>decl-specifier-seq</I> shall be followed by
one or more <I>init-declarator</I>s, each of which shall have a
non-empty <I>initializer</I> of either of the following forms:</P>

<UL>
<TT>=</TT> <I>assignment-expression</I><BR>
<TT>(</TT> <I>assignment-expression</I> <TT>)</TT>
</UL>

</BLOCKQUOTE>

<P>It was intended that <TT>auto</TT> could be used only at the
top level of a declaration, but it is not clear whether this wording
is sufficient to forbid usage like the following:</P>

<PRE>
    template &lt;class T&gt; struct A {};
    template &lt;class T&gt; void f(A&lt;T&gt; x) {}

    void g()
    {
        f(A&lt;short&gt;());

        A&lt;auto&gt; x = A&lt;short&gt;();
    }
</PRE>

<P><B>Notes from the February, 2008 meeting:</B></P>

<P>It was agreed that the example should be ill-formed.</P>

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

<P>Change 9.2.9.7 [<A href="https://wg21.link/dcl.spec.auto#3">dcl.spec.auto</A>] paragraph 3 as follows:</P>

<BLOCKQUOTE>

...<DEL>The</DEL> <INS><TT>auto</TT> shall appear as one of the
<I>decl-specifier</I>s in the <I>decl-specifier-seq</I> and the</INS>
<I>decl-specifier-seq</I> shall be followed by one or more
<I>init-declarator</I>s, each of which shall have a non-empty
<I>initializer</I>.

</BLOCKQUOTE>

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