1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: libcpp-has-no-threads
10 
11 // <thread>
12 
13 // class thread
14 
15 // thread& operator=(thread&& t);
16 
17 #include <thread>
18 #include <cassert>
19 #include <utility>
20 
21 #include "test_macros.h"
22 
23 class G
24 {
25     int alive_;
26 public:
27     static int n_alive;
28     static bool op_run;
29 
30     G() : alive_(1) {++n_alive;}
31     G(const G& g) : alive_(g.alive_) {++n_alive;}
32     ~G() {alive_ = 0; --n_alive;}
33 
34     void operator()()
35     {
36         assert(alive_ == 1);
37         assert(n_alive >= 1);
38         op_run = true;
39     }
40 };
41 
42 int G::n_alive = 0;
43 bool G::op_run = false;
44 
45 int main(int, char**)
46 {
47     assert(G::n_alive == 0);
48     assert(!G::op_run);
49     {
50         G g;
51         assert(G::n_alive == 1);
52         assert(!G::op_run);
53 
54         std::thread t0(g);
55         std::thread::id id = t0.get_id();
56 
57         std::thread t1;
58         t1 = std::move(t0);
59         assert(t1.get_id() == id);
60         assert(t0.get_id() == std::thread::id());
61 
62         t1.join();
63         assert(G::n_alive == 1);
64         assert(G::op_run);
65     }
66     assert(G::n_alive == 0);
67     assert(G::op_run);
68 
69     return 0;
70 }
71