title: C++ Using lambda for implicit constructor call expecting a function pointer
body: <p>I am trying to implicitly construct an object from a lambda function. The constructor of the object takes a function pointer as parameter. But the code [ 1 ] doesn't compile with the message:</p>
  
  <pre><code>6 : &lt;source&gt;:6:5: note: candidate constructor not viable: no known conversion from '(lambda at /tmp/compiler-explorer-compiler117117-54-dfxyju.lkw98/example.cpp:22:14)' to 'Bar' (aka 'bool (*)()') for 1st argument
      Foo(Bar b) : m_b{b} {}
  </code></pre>
  
  <p>But the standard states that a lambda function is implicitly convertible to a function pointer with the same parameter and return type [ 2 ]. This should be applicable here and therefore I would expect the constructor to be callable.</p>
  
  <p>So why doesn't the code compile? Thanks for your explanations!</p>
  
  <hr>
  
  <p>[ 1 ] Code example:</p>
  
  <pre><code>using Bar = bool(*)();
  
  class Foo
  {
  public:
      Foo(Bar b) : m_b{b} {}
  private:
      Bar m_b;
  };
  
  int main()
  {   
      // working
      Foo f1 ( [](){ return true; });
      Foo f2 = Bar( [](){ return true; });
  
      // working implicit conversion
      bool(*tmp)() = []() { return true; };
      Foo f3 = tmp;
  
      // not working
      Foo f4 = [](){ return true; };
  
      return 0;
  }
  </code></pre>
  
  <p><a href="https://godbolt.org/g/QE4v1Z" rel="nofollow noreferrer">https://godbolt.org/g/QE4v1Z</a></p>
  
  <hr>
  
  <p>[ 2 ] The <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf" rel="nofollow noreferrer">C++14 Standard</a> states in section 5.1.2 that:</p>
  
  <blockquote>
    <p>The closure type for a lambda-expression with no lambda-capture has a public non-virtual non-explicit const conversion function to pointer to function having the same parameter and return types as the closure type’s function call operator. The value returned by this conversion function shall be the address of a function that, when invoked, has the same effect as invoking the closure type’s function call operator.</p>
  </blockquote>
  
  <p>Which means the lambda should be implicitly (non-explicit) convertable to the function pointer. </p>
  
  <hr>
  
  <p>tested with:</p>
  
  <ul>
  <li>Clang5.0.0 -std=c++14</li>
  <li>MSVC14.12 /permissive-</li>
  </ul>