title: Function pointers as template arguments
body: <p>In the following C++ code, the line <code>bar&lt;func_ptr&gt;(); //does not work</code> causes a compilation error:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  void foo(){
      cout&lt;&lt;"Hello world";
  };
  
  template&lt;void(*func)()&gt; 
  void bar(){
      (*func)();
  }
  
  int main() {
      using fun_ptr_type= void(*)();
      constexpr fun_ptr_type func_ptr=&amp;foo;
  
      bar&lt;&amp;foo&gt;();     //works
      bar&lt;func_ptr&gt;(); //does not work
      return 0;
  }
  </code></pre>
  
  <p>The output of g++ is this:</p>
  
  <pre><code>src/main.cpp: In function ‘int main()’:
  src/main.cpp:19:16: error: no matching function for call to ‘bar()’
    bar&lt;func_ptr&gt;(); //does not work
                  ^
  src/main.cpp:10:6: note: candidate: template&lt;void (* func)()&gt; void bar()
   void bar(){
        ^~~
  src/main.cpp:10:6: note:   template argument deduction/substitution failed:
  src/main.cpp:19:16: error: ‘(fun_ptr_type)func_ptr’ is not a valid template argument for ty
  pe ‘void (*)()’
    bar&lt;func_ptr&gt;(); //does not work
                  ^
  src/main.cpp:19:16: error: it must be the address of a function with external linkage
  </code></pre>
  
  <p>I do not understand why it works when I directly pass the address of <code>foo</code> as a template argument but when I pass the constexpr <code>func_ptr</code>, the code does not compile anymore even though it holds exactly that address of <code>foo</code> at compilation time. Can someone explain this to me?</p>
  
  <p>EDIT: My g++ version is</p>
  
  <pre><code>$ g++ --version
  g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
  Copyright (C) 2016 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  </code></pre>