<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 486</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="486"></A><H4>486.
  
Invalid return types and template argument deduction
</H4>
<B>Section: </B>13.10.3&#160; [<A href="https://wg21.link/temp.deduct">temp.deduct</A>]
 &#160;&#160;&#160;

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

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

 <B>Date: </B>16 Nov 2004<BR>


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

<P>According to 13.10.3 [<A href="https://wg21.link/temp.deduct#2">temp.deduct</A>] paragraph 2,</P>

<BLOCKQUOTE>

If a substitution in a template parameter or in the function type
of the function template results in an invalid type, type
deduction fails.

</BLOCKQUOTE>

<P>That would seem to apply to cases like the following:</P>

<PRE>
    template &lt;class T&gt; T f(T&amp;){}
    void f(const int*){}
    int main() {
      int a[5];
      f(a);
    }
</PRE>

<P>Here, the return type of <TT>f</TT> is deduced as
<TT>int[5]</TT>, which is invalid according to 9.3.4.6 [<A href="https://wg21.link/dcl.fct#6">dcl.fct</A>] paragraph 6.  The outcome of this example, then,
should presumably be that type deduction fails and overload
resolution selects the non-template function.  However, the list
of reasons in 13.10.3 [<A href="https://wg21.link/temp.deduct">temp.deduct</A>] for which type
deduction can fail does not include function and array types as a
function return type.  Those cases should be added to the
list.</P>

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

<P>Change the last sub-bullet of 13.10.3 [<A href="https://wg21.link/temp.deduct#2">temp.deduct</A>] paragraph 2
as indicated:</P>

<UL><LI><P>Attempting to create a function type in which a parameter
has a type of <TT>void</TT><INS>, or in which the return type is a
function type or array type</INS>.</P></LI></UL>

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