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-exceptions 10 // UNSUPPORTED: libcpp-has-no-threads 11 // UNSUPPORTED: c++03 12 13 // <future> 14 15 // class future<R> 16 17 // ~future(); 18 19 #include <future> 20 #include <cassert> 21 22 #include "test_macros.h" 23 #include "test_allocator.h" 24 main(int,char **)25int main(int, char**) 26 { 27 assert(test_alloc_base::alloc_count == 0); 28 { 29 typedef int T; 30 std::future<T> f; 31 { 32 std::promise<T> p(std::allocator_arg, test_allocator<T>()); 33 assert(test_alloc_base::alloc_count == 1); 34 f = p.get_future(); 35 assert(test_alloc_base::alloc_count == 1); 36 assert(f.valid()); 37 } 38 assert(test_alloc_base::alloc_count == 1); 39 assert(f.valid()); 40 } 41 assert(test_alloc_base::alloc_count == 0); 42 { 43 typedef int& T; 44 std::future<T> f; 45 { 46 std::promise<T> p(std::allocator_arg, test_allocator<int>()); 47 assert(test_alloc_base::alloc_count == 1); 48 f = p.get_future(); 49 assert(test_alloc_base::alloc_count == 1); 50 assert(f.valid()); 51 } 52 assert(test_alloc_base::alloc_count == 1); 53 assert(f.valid()); 54 } 55 assert(test_alloc_base::alloc_count == 0); 56 { 57 typedef void T; 58 std::future<T> f; 59 { 60 std::promise<T> p(std::allocator_arg, test_allocator<T>()); 61 assert(test_alloc_base::alloc_count == 1); 62 f = p.get_future(); 63 assert(test_alloc_base::alloc_count == 1); 64 assert(f.valid()); 65 } 66 assert(test_alloc_base::alloc_count == 1); 67 assert(f.valid()); 68 } 69 assert(test_alloc_base::alloc_count == 0); 70 71 return 0; 72 } 73