title: clang vs gcc - passing non-copyable type to variadic generic lambda
body: <p><a href="https://godbolt.org/g/HxMq0K" rel="nofollow">gcc.godbolt.org link</a></p>
  
  <p>I've encountered a situation where passing a non-copyable type (by reference) to a variadic generic lambda after a copyable type (by copy) causes a compilation error on <code>g++</code> (both on <code>5.3</code> and <code>6.1</code>) but not on <code>clang++</code>.</p>
  
  <pre><code>int main()
  {
      auto f = [](auto&amp;&amp;...)
      {
      };
  
      non_copyable nc;
  
      f(nc); // ok on both compilers
      f(nc, int{}); // ok on both compilers
      f(int{}, nc); // error only on gcc 
  } 
  </code></pre>
  
  <p><code>g++</code> gives the following error for the <code>f(int{}, nc)</code> call: </p>
  
  <pre><code>x.cpp: In function ‘void test()’:
  x.cpp:19:19: error: use of deleted function ‘non_copyable::non_copyable(const non_copyable&amp;)’
       f(int{}, nc);
                  ^
  x.cpp:8:5: note: declared here
       non_copyable(const non_copyable&amp;) = delete;
       ^~~~~~~~~~~~
  </code></pre>
  
  <p>It seems that if the first argument is passed by copy, all the other arguments are passed by copy as well. This looks like a bug, because using an hand-written callable object that should be equivalent to the lambda works on both compilers:</p>
  
  <pre><code>// should be equivalent to `[](auto&amp;&amp;...){ }`
  struct do_nothing
  {
      template &lt;typename... Ts&gt;
      constexpr auto operator()(Ts&amp;&amp;...) const noexcept
      {
      }
  };
  
  // ...
  
  do_nothing{}(nc); // ok on both compilers
  do_nothing{}(nc, int{}); // ok on both compilers
  do_nothing{}(int{}, nc); // ok on both compilers
  </code></pre>
  
  <p>There seems to be an inconsistency between callable objects and generic variadic lambdas on <code>g++</code>.</p>
  
  <p>Is this a <code>g++</code> bug? Or is there something I am missing?</p>