title: Template argument deduction for an argument of a function type
body: <p>Consider the following program.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template &lt;typename T&gt;
  void f( void ( *fn )( T ) )
  {
      fn( 42 );
  }
  
  void g( int x )
  {
      std::cout &lt;&lt; "g( " &lt;&lt; x &lt;&lt; " );\n";
  }
  
  int main()
  {
      f( g );
  }
  </code></pre>
  
  <p>The program compiles successfully and its output is</p>
  
  <pre><code>g( 42 );
  </code></pre>
  
  <p>Now let's rename the non-template function <code>g</code> to <code>f</code>.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template &lt;typename T&gt;
  void f( void ( *fn )( T ) )
  {
      fn( 42 );
  }
  
  void f( int x )
  {
      std::cout &lt;&lt; "f( " &lt;&lt; x &lt;&lt; " );\n"; 
  }
  
  int main()
  {
      f( f );
  }
  </code></pre>
  
  <p>Now the program is not compiled by gcc HEAD 10.0.0 20200 and clang HEAD 10.0.0 but compiled successfully by Visual C++ 2019.. </p>
  
  <p>For example the compiler gcc issues the following set of messages.</p>
  
  <pre><code>prog.cc: In function 'int main()':
  prog.cc:22:10: error: no matching function for call to 'f(&lt;unresolved overloaded function type&gt;)'
     22 |     f( f );
        |          ^
  prog.cc:4:6: note: candidate: 'template&lt;class T&gt; void f(void (*)(T))'
      4 | void f( void ( *fn )( T ) )
        |      ^
  prog.cc:4:6: note:   template argument deduction/substitution failed:
  prog.cc:22:10: note:   couldn't deduce template parameter 'T'
     22 |     f( f );
        |          ^
  prog.cc:14:6: note: candidate: 'void f(int)'
     14 | void f( int x )
        |      ^
  prog.cc:14:13: note:   no known conversion for argument 1 from '&lt;unresolved overloaded function type&gt;' to 'int'
     14 | void f( int x )
        |         ~~~~^
  </code></pre>
  
  <p>So a question arises: should the code be compiled and what is the reason that the code is not compiled by gcc and clang?</p>