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, c++98, c++03
10 
11 // <thread>
12 
13 // class thread
14 
15 // thread& operator=(thread&& t);
16 
17 #include <thread>
18 #include <cassert>
19 
20 class G
21 {
22     int alive_;
23 public:
24     static int n_alive;
25     static bool op_run;
26 
27     G() : alive_(1) {++n_alive;}
28     G(const G& g) : alive_(g.alive_) {++n_alive;}
29     ~G() {alive_ = 0; --n_alive;}
30 
31     void operator()(int i, double j)
32     {
33         assert(alive_ == 1);
34         assert(n_alive >= 1);
35         assert(i == 5);
36         assert(j == 5.5);
37         op_run = true;
38     }
39 };
40 
41 int G::n_alive = 0;
42 bool G::op_run = false;
43 
44 int main(int, char**)
45 {
46     {
47         assert(G::n_alive == 0);
48         assert(!G::op_run);
49         {
50         G g;
51         std::thread t0(g, 5, 5.5);
52         std::thread::id id = t0.get_id();
53         std::thread t1;
54         t1 = std::move(t0);
55         assert(t1.get_id() == id);
56         assert(t0.get_id() == std::thread::id());
57         t1.join();
58         }
59         assert(G::n_alive == 0);
60         assert(G::op_run);
61     }
62 
63   return 0;
64 }
65