title: Converting a forwarding lambda to a function pointer
body: <p>Here are two things that work. We can instantiate a forwarding function template to get a function pointer taking an lvalue:</p>
  
  <pre><code>template &lt;class T&gt;
  void f(T &amp;&amp;) {}
  
  void(*p)(int &amp;) = f; // Cool!
  </code></pre>
  
  <p>We can also convert a non-capturing generic lambda taking an lvalue to a function pointer taking an lvalue:</p>
  
  <pre><code>auto l = [](auto &amp;) { };
  
  void (*lp)(int &amp;) = l; // Still cool!
  </code></pre>
  
  <p>But apparently none of GCC and Clang will convert a forwarding generic lambda into a function pointer taking an lvalue:</p>
  
  <pre><code>auto l = [](auto &amp;&amp;) { };
  
  void (*lp)(int &amp;) = l; // Not cool!
  </code></pre>
  
  <p>GCC outputs:</p>
  
  <pre><code>&lt;source&gt;:9:21: error: invalid user-defined conversion from '&lt;lambda(auto:1&amp;&amp;)&gt;' to 'void (*)(int&amp;)' [-fpermissive]
   void (*lp)(int &amp;) = l;
                       ^
  </code></pre>
  
  <p>Clang outputs:</p>
  
  <pre><code>&lt;source&gt;:9:8: fatal error: no viable conversion from '(lambda at &lt;source&gt;:7:10)' to 'void (*)(int &amp;)'
  void (*lp)(int &amp;) = l;
         ^            ~
  &lt;source&gt;:7:10: note: candidate template ignored: could not match 'type-parameter-0-0 &amp;&amp;' against 'int &amp;'
  auto l = [](auto &amp;&amp;) { };
           ^
  </code></pre>
  
  <p>This is all despite the fact that a member function pointer taking an lvalue <em>can</em> be obtained from the forwarding lambda:</p>
  
  <pre><code>auto lmp = &amp;decltype(l)::operator()&lt;int &amp;&gt;;
  
  template &lt;class...&gt;
  struct check;
  check&lt;decltype(lmp)&gt; c;
  </code></pre>
  
  <p>... which outputs the type <code>void (&lt;lambda(auto:1&amp;&amp;)&gt;::*)(int&amp;) const</code> as expected.</p>
  
  <p>I thought that reference collapsing rules were inherent to any template instantiation, and expected this to work. Do both Clang and GCC have a bug, or is that not actually provided by the Standard?</p>