1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
16 // promise& operator=(promise&& rhs);
21 #include "test_macros.h"
22 #include "test_allocator.h"
26 test_allocator_statistics alloc_stats
;
27 assert(alloc_stats
.alloc_count
== 0);
29 std::promise
<int> p0(std::allocator_arg
, test_allocator
<int>(&alloc_stats
));
30 std::promise
<int> p(std::allocator_arg
, test_allocator
<int>(&alloc_stats
));
31 assert(alloc_stats
.alloc_count
== 2);
33 assert(alloc_stats
.alloc_count
== 1);
34 std::future
<int> f
= p
.get_future();
35 assert(alloc_stats
.alloc_count
== 1);
37 #ifndef TEST_HAS_NO_EXCEPTIONS
43 catch (const std::future_error
& e
)
45 assert(e
.code() == make_error_code(std::future_errc::no_state
));
48 assert(alloc_stats
.alloc_count
== 1);
50 assert(alloc_stats
.alloc_count
== 0);
52 std::promise
<int&> p0(std::allocator_arg
, test_allocator
<int>(&alloc_stats
));
53 std::promise
<int&> p(std::allocator_arg
, test_allocator
<int>(&alloc_stats
));
54 assert(alloc_stats
.alloc_count
== 2);
56 assert(alloc_stats
.alloc_count
== 1);
57 std::future
<int&> f
= p
.get_future();
58 assert(alloc_stats
.alloc_count
== 1);
60 #ifndef TEST_HAS_NO_EXCEPTIONS
66 catch (const std::future_error
& e
)
68 assert(e
.code() == make_error_code(std::future_errc::no_state
));
71 assert(alloc_stats
.alloc_count
== 1);
73 assert(alloc_stats
.alloc_count
== 0);
75 std::promise
<void> p0(std::allocator_arg
, test_allocator
<void>(&alloc_stats
));
76 std::promise
<void> p(std::allocator_arg
, test_allocator
<void>(&alloc_stats
));
77 assert(alloc_stats
.alloc_count
== 2);
79 assert(alloc_stats
.alloc_count
== 1);
80 std::future
<void> f
= p
.get_future();
81 assert(alloc_stats
.alloc_count
== 1);
83 #ifndef TEST_HAS_NO_EXCEPTIONS
89 catch (const std::future_error
& e
)
91 assert(e
.code() == make_error_code(std::future_errc::no_state
));
94 assert(alloc_stats
.alloc_count
== 1);
96 assert(alloc_stats
.alloc_count
== 0);