title: SFINAE on functions with default parameters - free function vs operator()
body: <p>I was playing around with <a href="https://stackoverflow.com/a/52369813/9528746">this answer</a> to investigate how it handles functions with default parameters. To my surprise, the results are different for free functions and <code>operator()</code>:</p>
  
  <pre><code>template &lt;typename F&gt;
  auto func(F f) -&gt; decltype(f(42))
  {
      int a = 51;
      return f(51);
  }
  
  template &lt;typename F&gt;
  auto func(F f) -&gt; decltype(f(42, 42))
  {
      int a = 0;
      int b = 10;
      return f(a, b);
  }
  
  int defaultFree(int a, int b = 0)
  {
      return a;
  }
  
  auto defaultLambda = [](int a, int b = 0)
  {
      return a;
  };
  
  int foo()
  {
      return func(defaultFree);  
      //return func(defaultLambda);
  }
  </code></pre>
  
  <p><a href="https://godbolt.org/z/gdy3Qr" rel="noreferrer">Godbolt link</a></p>
  
  <p>The <code>func(defaultFree)</code> version above compiles while both <code>func</code> templates are available. As expected, it picks the second one because default parameters are not considered part of the function signature. Indeed, removing the second <code>func</code> template causes a compilation error.</p>
  
  <p>However, <code>func(defaultLambda)</code> does <a href="https://godbolt.org/z/ZFVMiA" rel="noreferrer"><strong>not</strong> compile</a> due to ambiguity: Both <code>func</code> templates match. Removing either one makes this version compile.</p>
  
  <p><em>(The same happens if you manually write a <code>struct</code> with a similar <code>operator()</code>, of course. Latest <code>gcc</code>, <code>clang</code> and <code>MSVC</code> all agree on it, too.)</em></p>
  
  <p>What is the reason that the default parameter is considered inside the unevaluated SFINAE context for <code>operator()</code> but not for the free function?</p>