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(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::move(p0
));
31 assert(alloc_stats
.alloc_count
== 1);
32 std::future
<int> f
= p
.get_future();
33 assert(alloc_stats
.alloc_count
== 1);
35 #ifndef TEST_HAS_NO_EXCEPTIONS
41 catch (const std::future_error
& e
)
43 assert(e
.code() == make_error_code(std::future_errc::no_state
));
45 assert(alloc_stats
.alloc_count
== 1);
48 assert(alloc_stats
.alloc_count
== 0);
50 std::promise
<int&> p0(std::allocator_arg
, test_allocator
<int>(&alloc_stats
));
51 std::promise
<int&> p(std::move(p0
));
52 assert(alloc_stats
.alloc_count
== 1);
53 std::future
<int&> f
= p
.get_future();
54 assert(alloc_stats
.alloc_count
== 1);
56 #ifndef TEST_HAS_NO_EXCEPTIONS
62 catch (const std::future_error
& e
)
64 assert(e
.code() == make_error_code(std::future_errc::no_state
));
66 assert(alloc_stats
.alloc_count
== 1);
69 assert(alloc_stats
.alloc_count
== 0);
71 std::promise
<void> p0(std::allocator_arg
, test_allocator
<void>(&alloc_stats
));
72 std::promise
<void> p(std::move(p0
));
73 assert(alloc_stats
.alloc_count
== 1);
74 std::future
<void> f
= p
.get_future();
75 assert(alloc_stats
.alloc_count
== 1);
77 #ifndef TEST_HAS_NO_EXCEPTIONS
83 catch (const std::future_error
& e
)
85 assert(e
.code() == make_error_code(std::future_errc::no_state
));
87 assert(alloc_stats
.alloc_count
== 1);
90 assert(alloc_stats
.alloc_count
== 0);