move2.pass.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // UNSUPPORTED: libcpp-has-no-threads
  11. // UNSUPPORTED: c++98, c++03
  12. // <thread>
  13. // class thread
  14. // thread& operator=(thread&& t);
  15. #include <thread>
  16. #include <exception>
  17. #include <cstdlib>
  18. #include <cassert>
  19. class G
  20. {
  21. int alive_;
  22. public:
  23. static int n_alive;
  24. static bool op_run;
  25. G() : alive_(1) {++n_alive;}
  26. G(const G& g) : alive_(g.alive_) {++n_alive;}
  27. ~G() {alive_ = 0; --n_alive;}
  28. void operator()(int i, double j)
  29. {
  30. assert(alive_ == 1);
  31. assert(n_alive >= 1);
  32. assert(i == 5);
  33. assert(j == 5.5);
  34. op_run = true;
  35. }
  36. };
  37. int G::n_alive = 0;
  38. bool G::op_run = false;
  39. void f1()
  40. {
  41. std::_Exit(0);
  42. }
  43. int main()
  44. {
  45. std::set_terminate(f1);
  46. {
  47. G g;
  48. std::thread t0(g, 5, 5.5);
  49. std::thread::id id = t0.get_id();
  50. std::thread t1;
  51. t0 = std::move(t1);
  52. assert(false);
  53. }
  54. }