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