title: Template deduction failed on the heap but works on the stack
body: <p>I have a problem with a templated class.
  When I instantiate the class on the <strong>stack, it works</strong>.
  When I instantiate the same class on the <strong>heap, it fails. (argument deduction)</strong>
  I don't understand why...</p>
  
  <p><strong>Infos:</strong> I'm using gcc 7.2.0 with c++17.</p>
  
  <p>here an example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;memory&gt;
  
  template &lt;class ReturnType, class ClassName, class... Args&gt;
  class MethodPtr
  {
  public:
      typedef ReturnType (ClassName::*Method)(Args...);
  
      MethodPtr(ClassName* ptr, Method m) : _p(ptr), _m(m)
      {
          (ptr-&gt;*m)(4);
      }
  
      ClassName* _p;
      Method _m;
  };
  
  class Example
  {
  public:
      Example()
      {
          dotest(this, &amp;Example::func);
      }
  
      template &lt;class Ptr, class Func&gt;
      void dotest(Ptr ptr, Func func)
      {
          // works
          MethodPtr(ptr, func);
  
          // don't works
          //std::make_unique&lt;MethodPtr&gt;(ptr, func);
          //new MethodPtr(ptr, func);
  
          //works
          std::make_unique&lt;decltype(MethodPtr(ptr, func))&gt;(ptr, func);
          new decltype(MethodPtr(ptr, func))(ptr, func);
      }
  
      void func(int i)
      {
          std::cout &lt;&lt; i &lt;&lt; std::endl;
      }
  };
  
  int main()
  {
      Example example;
  }
  </code></pre>
  
  <p>Do you have a solution to avoid the decltype?</p>
  
  <p>Thanks,</p>