title: Segmentation fault error occurs when gcc, but there is no problem with clang
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;thread&gt;
  #include &lt;chrono&gt;
  #include &lt;functional&gt;
  
  template &lt;typename F, typename... Ts&gt;
  inline void FuncDetach(F &amp;&amp;f, Ts &amp;&amp;...args)
  {
      std::thread th{[&amp;f, &amp;args...]() {
          do
          {
              auto func = std::bind(std::forward&lt;F&gt;(f), std::forward&lt;Ts&gt;(args)...);
              func(args...);
          } while (true);
      }};
      th.detach();
  }
  
  auto func()
  {
      std::cout &lt;&lt; &quot;normal func&quot; &lt;&lt; std::endl;
  }
  
  class CL
  {
  public:
      auto func() {std::cout &lt;&lt; &quot;member func&quot; &lt;&lt; std::endl;}
  };
  
  int main()
  {
      FuncDetach(func); // gcc and clang no problem
  
      CL c;
      FuncDetach(&amp;CL::func, &amp;c); // segmentation fault in gcc, but not in clang
      std::this_thread::sleep_for(std::chrono::minutes(2));
      return 0;
  }
  
  </code></pre>
  <p>There is only &quot;normal func&quot; output in gcc, and then &quot;Segmentation fault&quot; appears. &quot;normal func&quot; and &quot;member func&quot; in clang will always output.</p>
  <p>I don't think this has anything to do with the life cycle of c, because it is obvious that c has not been destroyed. At the same time, I also noticed that -lpthread is not required for compiling with clang. So, can someone tell me what the problem is? Thank you very much!</p>