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