fork download
  1. #include <thread>
  2.  
  3. class SomeClass {};
  4.  
  5. SomeClass& ProduceDeadReference()
  6. {
  7. SomeClass sc;
  8. SomeClass* p = &sc; // заткнём warning
  9. return *p;
  10. }
  11.  
  12. class Container
  13. {
  14. SomeClass& ref;
  15. public:
  16. Container(SomeClass& v) : ref(v) {}
  17. };
  18.  
  19. void ThreadProc(Container* c)
  20. {
  21. // пользуемся, вылетаем
  22. }
  23.  
  24. int main()
  25. {
  26. Container c(ProduceDeadReference());
  27. std::thread t(ThreadProc, &c);
  28. return 0;
  29. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/home/0PhLKx/cczWevXY.o: In function `std::thread::thread<void (&)(Container*), Container*>(void (&)(Container*), Container*&&)':
prog.cpp:(.text._ZNSt6threadC2IRFvP9ContainerEIS2_EEEOT_DpOT0_[_ZNSt6threadC5IRFvP9ContainerEIS2_EEEOT_DpOT0_]+0x2): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty