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 // <future> 13 14 // class promise<R> 15 16 // promise(promise&& rhs); 17 18 #include <future> 19 #include <cassert> 20 21 #include "../test_allocator.h" 22 23 int main() 24 { 25 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 26 assert(test_alloc_base::count == 0); 27 { 28 std::promise<int> p0(std::allocator_arg, test_allocator<int>()); 29 std::promise<int> p(std::move(p0)); 30 assert(test_alloc_base::count == 1); 31 std::future<int> f = p.get_future(); 32 assert(test_alloc_base::count == 1); 33 assert(f.valid()); 34 try 35 { 36 f = p0.get_future(); 37 assert(false); 38 } 39 catch (const std::future_error& e) 40 { 41 assert(e.code() == make_error_code(std::future_errc::no_state)); 42 } 43 assert(test_alloc_base::count == 1); 44 } 45 assert(test_alloc_base::count == 0); 46 { 47 std::promise<int&> p0(std::allocator_arg, test_allocator<int>()); 48 std::promise<int&> p(std::move(p0)); 49 assert(test_alloc_base::count == 1); 50 std::future<int&> f = p.get_future(); 51 assert(test_alloc_base::count == 1); 52 assert(f.valid()); 53 try 54 { 55 f = p0.get_future(); 56 assert(false); 57 } 58 catch (const std::future_error& e) 59 { 60 assert(e.code() == make_error_code(std::future_errc::no_state)); 61 } 62 assert(test_alloc_base::count == 1); 63 } 64 assert(test_alloc_base::count == 0); 65 { 66 std::promise<void> p0(std::allocator_arg, test_allocator<void>()); 67 std::promise<void> p(std::move(p0)); 68 assert(test_alloc_base::count == 1); 69 std::future<void> f = p.get_future(); 70 assert(test_alloc_base::count == 1); 71 assert(f.valid()); 72 try 73 { 74 f = p0.get_future(); 75 assert(false); 76 } 77 catch (const std::future_error& e) 78 { 79 assert(e.code() == make_error_code(std::future_errc::no_state)); 80 } 81 assert(test_alloc_base::count == 1); 82 } 83 assert(test_alloc_base::count == 0); 84 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 85 } 86