Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The second <code>void foo(...</code> is an overload (and not a specialization) which is not visible at the definition of <code>foo_fun::fun</code> so it won't be found in the context of the template definition. Because <code>T*</code> is a dependent type, resolution of <code>foo</code> in the expression <code>foo((T*)0, 0)</code> will be delayed until template instantiation time and the context of the instantiation will also be considered. However, 14.6.4.2 of the standard says that if the function name is an <em>unqualified-id</em> but not a <em>template-id</em> then for non-ADL lookup only functions visible at the point of definition of the template are considered. There are no function arguments from the <code>Foo</code> namespace so no argument dependent lookup occurs, hence the template version of <code>foo</code> is called and not the non-template overload.</p> <p>Many thanks to litb for the corrections to this answer.</p> <p>If you made it a specialization as below, then as specializations are chosen at template instantiation time, the specialization can be called so long as the relevant specialization is visible at the point at which the function template is first instantiated for <code>int</code>.</p> <pre><code>namespace Foo { template&lt;&gt; void foo&lt;int&gt;(int *, int) { puts("int"); } } </code></pre> <p>Chapter 14 of the current standard, but it's not very readable :)</p> <p>Edit: If I had to pick the most relevant part of the standard it would probably be 14.6 [temp.res] para 9. (Slightly abbreviated) If a name does not depend on a <em>template-parameter</em>, a declaration for that name shall be in scope at the point at where the name appears in the template definition; the name is bound to the declaration found at that point and this binding is not affected by declarations that are visible at the point of instantiation.</p> <p>Edit, edit: But you also need to take into account 14.6.4.2 [temp.dep.candidate]. It is very difficult and dangerous to try and reference the standard because of all the interdependencies, this answer is a case in point.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload