<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 2092</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="2092"></A><H4>2092.
  
Deduction failure and overload resolution
</H4>
<B>Section: </B>13.10.4&#160; [<A href="https://wg21.link/temp.over">temp.over</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Fedor Sergeev
 &#160;&#160;&#160;

 <B>Date: </B>2015-03-06<BR>


<P>[Accepted as a DR at the March, 2018 (Jacksonville) meeting.]</P>



<P>Given an example like</P>

<PRE>
  template &lt;class T = int&gt; void foo(T*);

  void test()
  {
    foo(0);   //<SPAN CLASS="cmnt"> #1 valid?</SPAN>
    foo&lt;&gt;(0);  //<SPAN CLASS="cmnt"> #2 valid?</SPAN>
  }
</PRE>

<P>most/all implementations reject this code.  However, the wording
of the Standard only invokes 13.10.4 [<A href="https://wg21.link/temp.over">temp.over</A>]
(&#8220;Overload resolution&#8221;) in cases where there is more
than one function or function template, which is not the case here.
The current wording would appear to make this well-formed because
of the application of 13.10.2 [<A href="https://wg21.link/temp.arg.explicit#2">temp.arg.explicit</A>] paragraph 2.
Perhaps overload resolution should apply even when there is a single
function template?</P>

<P><B>Notes from the May, 2015 meeting:</B></P>

<P>This issue is mostly a duplicate of
<A HREF="1582.html">issue 1582</A>. However, CWG felt that it
should be clarified that overload resolution applies in all cases,
not just when templates are overloaded, so the issue is being left
open to deal with that aspect.</P>

<P><B>Proposed resolution (November, 2017)</B></P>

<OL>
<LI><P>Change 7.6.1.3 [<A href="https://wg21.link/expr.call#1">expr.call</A>] paragraph 1, splitting
it into three paragraphs, as follows:</P></LI>

<BLOCKQUOTE>

<P>A function call is a postfix expression followed by parentheses containing
a possibly empty, comma-separated list of <I>initializer-clause</I>s which
constitute the arguments to the function. The postfix expression shall have
function type or function pointer type. For a call to a non-member function
or to a static member function, the postfix expression shall be either an
lvalue that refers to a function (in which case the function-to-pointer
standard conversion (7.3.4 [<A href="https://wg21.link/conv.func">conv.func</A>]) is suppressed on the postfix
expression), or it shall have function pointer type.  <DEL>Calling a function
through an expression whose function type is different from the function
type of the called function's definition results in undefined behavior
(9.12 [<A href="https://wg21.link/dcl.link">dcl.link</A>]).</DEL>
</P>

<P>For a call to a non-static member function, the postfix expression shall
be an implicit (11.4.3 [<A href="https://wg21.link/class.mfct.non.static">class.mfct.non.static</A>], 11.4.9 [<A href="https://wg21.link/class.static">class.static</A>])
or explicit class member access (7.6.1.5 [<A href="https://wg21.link/expr.ref">expr.ref</A>]) whose
<I>id-expression</I> is a function member name, or a pointer-to-member
expression (7.6.4 [<A href="https://wg21.link/expr.mptr.oper">expr.mptr.oper</A>]) selecting a function member; the call
is as a member of the class object referred to by the object expression. In
the case of an implicit class member access, the implied object is the one
pointed to by <TT>this</TT>. [<I>Note:</I> A member function call of the
form <TT>f()</TT> is interpreted as <TT>(*this).f()</TT> (see
11.4.3 [<A href="https://wg21.link/class.mfct.non.static">class.mfct.non.static</A>]). &#8212;<I>end note</I>]</P>

<P>If a function or member function name is used, <DEL>the name can be
overloaded (Clause 12 [<A href="https://wg21.link/over">over</A>]), in which case</DEL> the
appropriate function <DEL>shall be selected</DEL> <INS>and the validity of
the call are determined</INS> according to the rules in
12.2 [<A href="https://wg21.link/over.match">over.match</A>]. If the selected function is non-virtual, or if
the <I>id-expression</I> in the class member access expression is a
qualified-id, that function is called. Otherwise, its final overrider
(11.7.3 [<A href="https://wg21.link/class.virtual">class.virtual</A>]) in the dynamic type of the object expression is
called; such a call is referred to as a <I>virtual function
call</I>. [<I>Note:</I> The dynamic type is the type of the object referred
to by the current value of the object expression. 11.9.5 [<A href="https://wg21.link/class.cdtor">class.cdtor</A>]
describes the behavior of virtual function calls when the object expression
refers to an object under construction or destruction.  &#8212;<I>end
note</I>]</P>

</BLOCKQUOTE>

<LI><P>Add the following to 7.6.1.3 [<A href="https://wg21.link/expr.call">expr.call</A>] as a new paragraph
before the existing paragraph 4:</P></LI>

<BLOCKQUOTE>

<P>
<INS>Calling a function through an expression whose function type is different from the function type of the called function's  definition results in undefined behavior (9.12 [<A href="https://wg21.link/dcl.link">dcl.link</A>]).</INS>
</P>

<P>When a function is called, each parameter (9.3.4.6 [<A href="https://wg21.link/dcl.fct">dcl.fct</A>])
shall be initialized...</P>

</BLOCKQUOTE>

<LI><P>Change Clause 12 [<A href="https://wg21.link/over#2">over</A>] paragraph 2 as follows:</P></LI>

<BLOCKQUOTE>

When <DEL>an overloaded</DEL> <INS>a</INS> function name is used in a call,
which <DEL>overloaded</DEL> function declaration is being
referenced <DEL>is</DEL> <INS>and the validity of the call are</INS>
determined by comparing the types of the arguments at the point of use with
the types of the parameters in the <DEL>overloaded</DEL> declarations that
are visible at the point of use. This function selection process is
called <I>overload resolution</I>...

</BLOCKQUOTE>

<LI><P>Change 13.10.4 [<A href="https://wg21.link/temp.over#1">temp.over</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

<DEL>A function template can be overloaded either by (non-template)
functions of its name or by (other) function templates of the same
name.</DEL> When a call to <DEL>that</DEL> <INS>the</INS> name <INS>of a
function or function template</INS> is written (explicitly, or implicitly
using the operator notation), template argument deduction...

</BLOCKQUOTE>

</OL>

<P>This resolution also resolves <A HREF="2241.html">issue 2241</A>.</P>

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