<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 561</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="561"></A><H4>561.
  
Internal linkage functions in dependent name lookup
</H4>
<B>Section: </B>13.8.4.2&#160; [<A href="https://wg21.link/temp.dep.candidate">temp.dep.candidate</A>]
 &#160;&#160;&#160;

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

 <B>Submitter: </B>Joaqu&#237;n L&#243;pez Mu&#241;oz
 &#160;&#160;&#160;

 <B>Date: </B>17 February 2006<BR>


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

<P>According to 13.8.4.2 [<A href="https://wg21.link/temp.dep.candidate">temp.dep.candidate</A>],</P>

<BLOCKQUOTE>

<P>For a function call that depends on a template parameter, if the
function name is an <I>unqualified-id</I> but not
a <I>template-id</I>, the candidate functions are found using the
usual lookup rules (6.5.3 [<A href="https://wg21.link/basic.lookup.unqual">basic.lookup.unqual</A>], 6.5.4 [<A href="https://wg21.link/basic.lookup.argdep">basic.lookup.argdep</A>]) except that:</P>

<UL>
<LI><P>For the part of the lookup using unqualified name lookup
(6.5.3 [<A href="https://wg21.link/basic.lookup.unqual">basic.lookup.unqual</A>]), only function declarations with
external linkage from the template definition context are
found.</P></LI>

<LI><P>For the part of the lookup using associated namespaces
(6.5.4 [<A href="https://wg21.link/basic.lookup.argdep">basic.lookup.argdep</A>]), only function declarations with
external linkage found in either the template definition context or
the template instantiation context are found.</P></LI>
</UL>

</BLOCKQUOTE>

<P>It is not at all clear why a call using a <I>template-id</I>
would be treated differently from one not using a <I>template-id</I>.
Furthermore, is it really necessary to exclude internal linkage
functions from the lookup?  Doesn't the ODR give implementations
sufficient latitude to handle this case without another wrinkle
on name lookup?</P>

<P>(See also <A HREF="524.html">issue 524</A>.)</P>

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

<P>The consensus of the group was that <I>template-id</I>s should not
be treated differently from <I>unqualified-id</I>s (although it's not
clear how argument-dependent lookup works for <I>template-id</I>s),
and that internal-linkage functions should be found by the lookup
(although they may result in errors if selected by overload
resolution).</P>

<P><B>Note (June, 2006):</B></P>

<P>Although the notes from the Berlin meeting indicate that
argument-dependent lookup for <I>template-id</I>s is under-specified
in the Standard, further examination indicates that that is not the
case: the note in 13.10.2 [<A href="https://wg21.link/temp.arg.explicit#8">temp.arg.explicit</A>] paragraph 8 clearly
indicates that argument-dependent lookup is to be performed for
<I>template-id</I>s, and 6.5.4 [<A href="https://wg21.link/basic.lookup.argdep#4">basic.lookup.argdep</A>] paragraph 4
describes the lookup performed:</P>

<BLOCKQUOTE>

When considering an associated namespace, the lookup is the same as
the lookup performed when the associated namespace is used as a
qualifier (6.5.5.3 [<A href="https://wg21.link/namespace.qual">namespace.qual</A>]) except that:

<UL>

<LI><P>Any <I>using-directive</I>s in the associated namespace are
ignored.</P></LI>

<LI><P>Any namespace-scope friend functions declared in associated
classes are visible within their respective namespaces even if they
are not visible during an ordinary lookup (11.8.4 [<A href="https://wg21.link/class.friend">class.friend</A>]).</P></LI>

</UL>

</BLOCKQUOTE>

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

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

<BLOCKQUOTE>

<P>In an expression of the form:</P>

<UL>
<I>postfix-expression</I> <TT>(</TT> <I>expression-list<SUB>opt</SUB></I> <TT>)</TT>
</UL>

<P>where the <I>postfix-expression</I> is an
<I>unqualified-id</I> <DEL>but not a <I>template-id</I></DEL>, the
<I>unqualified-id</I> denotes a <I>dependent name</I> if and only if
any of the expressions in the <I>expression-list</I> is a
type-dependent expression (13.8.3.3 [<A href="https://wg21.link/temp.dep.expr">temp.dep.expr</A>])...</P>

</BLOCKQUOTE>

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

<BLOCKQUOTE>

<P>For a function call that depends on a template parameter, if the
function name is an <I>unqualified-id</I> <DEL>but not a
<I>template-id</I></DEL>, or if the function is called using operator
notation, the candidate functions are found using the usual lookup
rules (6.5.3 [<A href="https://wg21.link/basic.lookup.unqual">basic.lookup.unqual</A>], 6.5.4 [<A href="https://wg21.link/basic.lookup.argdep">basic.lookup.argdep</A>]) except
that:</P>

<UL>
<LI><P>For the part of the lookup using unqualified name lookup
(6.5.3 [<A href="https://wg21.link/basic.lookup.unqual">basic.lookup.unqual</A>]), only function declarations <DEL>with
external linkage</DEL> from the template definition context are
found.</P></LI>

<LI><P>For the part of the lookup using associated namespaces
(6.5.4 [<A href="https://wg21.link/basic.lookup.argdep">basic.lookup.argdep</A>]), only function declarations <DEL>with
external linkage</DEL> found in either the template definition context
or the template instantiation context are found.</P></LI>

</UL>

</BLOCKQUOTE>

</OL>

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