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