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