Why can I not cast a lambda to void* then to a function pointer?
<p>I have a special case where I need to cast a lambda to void* in order to store it due to type erasure.</p>

<p>Everything works as expect for the first case but not the second and I'm wondering how to solve it and if this behavior is even defined to start with.</p>

<pre><code>int main()
{
    auto lambda = [](int x){
        std::cerr &lt;&lt; x &lt;&lt; std::endl;
    };

    //Cast lambda to void*
    void* vptr = static_cast&lt;void*&gt;(&amp;lambda);

    //Cast vptr back to lambda and call it
    (*static_cast&lt;decltype(&amp;lambda)&gt;(vptr))(10); //&lt;--- Ok, compiles and works

    //Cast vptr to function pointer
    (*static_cast&lt;void(**)(int)&gt;(vptr))(10); //&lt;--- Compiles but segmentation fault

    return 0;
}
</code></pre>