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 
12 // NOTE: std::terminate is called so the destructors are not invoked and the
13 // memory is not freed. This will cause ASAN to fail.
14 // XFAIL: asan
15 
16 // <thread>
17 
18 // class thread
19 
20 // thread& operator=(thread&& t);
21 
22 #include <thread>
23 #include <exception>
24 #include <cstdlib>
25 #include <cassert>
26 
27 class G
28 {
29     int alive_;
30 public:
31     static int n_alive;
32     static bool op_run;
33 
34     G() : alive_(1) {++n_alive;}
35     G(const G& g) : alive_(g.alive_) {++n_alive;}
36     ~G() {alive_ = 0; --n_alive;}
37 
38     void operator()()
39     {
40         assert(alive_ == 1);
41         assert(n_alive >= 1);
42         op_run = true;
43     }
44 
45     void operator()(int i, double j)
46     {
47         assert(alive_ == 1);
48         assert(n_alive >= 1);
49         assert(i == 5);
50         assert(j == 5.5);
51         op_run = true;
52     }
53 };
54 
55 int G::n_alive = 0;
56 bool G::op_run = false;
57 
58 void f1()
59 {
60     std::exit(0);
61 }
62 
63 int main()
64 {
65 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
66     std::set_terminate(f1);
67     {
68         std::thread t0(G(), 5, 5.5);
69         std::thread::id id = t0.get_id();
70         std::thread t1;
71         t0 = std::move(t1);
72         assert(false);
73     }
74 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
75 }
76