[Flang] Add semantics checks for CrayPointer usage in DSA list (#123171)
[llvm-project.git] / libcxx / test / std / thread / thread.threads / thread.thread.class / thread.thread.assign / move.pass.cpp
blobb5d0b9167102f5ea2e3f836f9871af4e916008d5
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: no-threads
11 // <thread>
13 // class thread
15 // thread& operator=(thread&& t);
17 #include <thread>
18 #include <cassert>
19 #include <utility>
21 #include "make_test_thread.h"
22 #include "test_macros.h"
24 class G
26 int alive_;
27 public:
28 static int n_alive;
29 static bool op_run;
31 G() : alive_(1) {++n_alive;}
32 G(const G& g) : alive_(g.alive_) {++n_alive;}
33 ~G() {alive_ = 0; --n_alive;}
35 void operator()()
37 assert(alive_ == 1);
38 assert(n_alive >= 1);
39 op_run = true;
43 int G::n_alive = 0;
44 bool G::op_run = false;
46 int main(int, char**)
48 assert(G::n_alive == 0);
49 assert(!G::op_run);
51 G g;
52 assert(G::n_alive == 1);
53 assert(!G::op_run);
55 std::thread t0 = support::make_test_thread(g);
56 std::thread::id id = t0.get_id();
58 std::thread t1;
59 t1 = std::move(t0);
60 assert(t1.get_id() == id);
61 assert(t0.get_id() == std::thread::id());
63 t1.join();
64 assert(G::n_alive == 1);
65 assert(G::op_run);
67 assert(G::n_alive == 0);
68 assert(G::op_run);
70 return 0;