title: "Unknown Type" runtime error when calling std::function
body: <p>I am using a library (<a href="http://microsoft.github.io/cpprestsdk/namespaces.html" rel="nofollow noreferrer">C++ REST SDK</a>) in which I can set a handler for a specific event. Precisely I set a close handler which gets called when a websocket connection gets closed by the client(me) or the server. The handler is set like this:</p>
  
  <pre><code>// WebsocketClient is my own custom class
  // m_pclClient holds the connection (of type websocket_callback_client)
  std::function&lt;void(web::websockets::client::websocket_close_status close_status, const utility::string_t &amp;reason, const std::error_code &amp;error)&gt; handler(std::bind(&amp;WebsocketClient::close_handler, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
  
  this-&gt;m_pclClient-&gt;set_close_handler(handler);
  </code></pre>
  
  <p>When I now close the connection the library handles the closing procedure and, after finishing the process, calls <code>handler</code> with its three parameters. </p>
  
  <p>When closing the connection an error occurs. I am not sure if it's a bug inside the library or my mistake. <code>gdb</code> output when closing the connection:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 0x7fffe1c23700 (LWP 13849)]
  0x00000000004e20b7 in std::__invoke_impl&lt;void, void (WebsocketClient::* const&amp;)(web::websockets::client::websocket_close_status, std::string const&amp;, std::error_code const&amp;), WebsocketClient*&amp;, web::websockets::client::websocket_close_status, std::string const&amp;, std::error_code const&amp;&gt;(std::__invoke_memfun_deref, void (WebsocketClient::* const&amp;)(web::websockets::client::websocket_close_status, std::string const&amp;, std::error_code const&amp;), WebsocketClient*&amp;, web::websockets::client::websocket_close_status&amp;&amp;, std::string const&amp;, std::error_code const&amp;) (__f=
      @0x80d290: (void (WebsocketClient::*)(WebsocketClient * const, web::websockets::client::websocket_close_status, const std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &amp;, const std::error_code &amp;)) 0x4cf120 &lt;WebsocketClient::close_handler(web::websockets::client::websocket_close_status, std::string const&amp;, std::error_code const&amp;)&gt;, __t=@0x80d2a0: 0x8081f8, 
      __args#0=&lt;unknown type in /path/to/executable, CU 0x1d28f4, DIE 0x21f672&gt;, __args#1="TLS Short Read", __args#2=...) at /usr/include/c++/6/functional:235
  235       return ((*std::forward&lt;_Tp&gt;(__t)).*__f)(std::forward&lt;_Args&gt;(__args)...);
  </code></pre>
  
  <p>There's obviously a problem with argument #0: <code>web::websockets::client::websocket_close_status close_status</code>.</p>
  
  <p>It seems that when the handler should be invoked, the type of the first argument is unknown. See in the gdb output: "__args#0= &lt; unknown type in /path/to/executable"</p>
  
  <p>Why is this happening and how to fix it?</p>