title: Candidate template ignored: deduced conflicting types for parameter: <const T &> vs <T &>
body: <p>I have a member function <code>_wrapper</code> in my class, that encapsulates some common logic around family of other functions. This wrapper function accepts pointer to function that is being wrapped and its arguments. </p>
  
  <p>Wrapper in my class is implemented similar to how it is done in this example class <code>Foo</code>:</p>
  
  <pre><code>#include &lt;functional&gt;
  
  class Foo
  {
  public:
      void bar1(int a)
      {
          /// No-op.
      }
  
      void bar1(int a, int b)
      {
          /// No-op.
      }
  
      void bar2(const int &amp; a)
      {
          /// No-op.
      }
  
      void foo(int x)
      {
          _wrapper_bar1(x);           /// No problems to deduce type
          _wrapper_bar2(x);           /// No problems to deduce type
  
          _wrapper(&amp;Foo::bar1, x);    /// Deduction fails
          _wrapper(&amp;Foo::bar2, x);    /// Deduction fails
      }
  
  private:
      template &lt;typename ...Args&gt;
      void _wrapper(void (Foo::*method) (Args ...), Args &amp;&amp; ...args)
      {
          /// Do some common stuff here...
  
          (this-&gt;*method)(std::forward&lt;Args&gt;(args)...);
      }
  
      template &lt;typename ...Args&gt;
      void _wrapper_bar1(Args &amp;&amp; ...args)
      {
          bar1(std::forward&lt;Args&gt;(args)...);
      }
  
      template &lt;typename ...Args&gt;
      void _wrapper_bar2(Args &amp;&amp; ...args)
      {
          bar2(std::forward&lt;Args&gt;(args)...);
      }
  };
  
  int main(int argc, char ** argv)
  {
      Foo().foo(123);
      return 0;
  }
  </code></pre>
  
  <p>When I pass an <code>lvalue</code>, <code>foo</code>'s argument <code>int x</code>, to the wrapper, <code>clang</code> compiler complaints that there is a conflict and deduction fails:</p>
  
  <pre><code>test.cpp:21:9: error: no matching member function for call to '_wrapper'
          _wrapper(&amp;Foo::bar1, x);    /// Deduction fails
          ^~~~~~~~
  test.cpp:27:10: note: candidate template ignored: deduced conflicting types for parameter 'Args' (&lt;int&gt; vs. &lt;int &amp;&gt;)
      void _wrapper(void (Foo::*method) (Args ...), Args &amp;&amp; ...args)
           ^
  test.cpp:22:9: error: no matching member function for call to '_wrapper'
          _wrapper(&amp;Foo::bar2, x);    /// Deduction fails
          ^~~~~~~~
  test.cpp:27:10: note: candidate template ignored: deduced conflicting types for parameter 'Args' (&lt;const int &amp;&gt; vs. &lt;int &amp;&gt;)
      void _wrapper(void (Foo::*method) (Args ...), Args &amp;&amp; ...args)
  </code></pre>
  
  <p>The thing is I don't understand why is this happening. It is okay to pass just <code>lvalue</code> alone, as it is done using <code>_wrapper_bar1</code> and <code>_wrapper_bar2</code>. And doing so does not rise any conflict of this sort, ie <code>const T &amp;</code> vs <code>T &amp;</code>. </p>
  
  <p>I know a way around this error: by casting <code>lvalue</code> to an <code>rvalue</code> using <code>std::move(x)</code>, but obviously it is not a fix, since move is not actually needed. Also, sometimes I need to use <code>x</code> after calling wrapper function, and using moved value is an UB.</p>
  
  <p>Probably my template is very broken and I am missing some obvious thing. I'd appreciate your help. </p>
  
  <p><strong>Edit:</strong> overloaded <code>Foo::bar1()</code></p>