| 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-threads |
| 10 |
// UNSUPPORTED: c++03 |
| 11 |
|
| 12 |
// <future> |
| 13 |
|
| 14 |
// class promise<R> |
| 15 |
|
| 16 |
// void promise::set_value(const R& r); |
| 17 |
|
| 18 |
#include <future> |
| 19 |
#include <cassert> |
| 20 |
|
| 21 |
#include "test_macros.h" |
| 22 |
|
| 23 |
struct A |
| 24 |
{ |
| 25 |
A() {} |
| 26 |
A(const A&) { |
| 27 |
TEST_THROW(10); |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
int main(int, char**) |
| 32 |
{ |
| 33 |
{ |
| 34 |
typedef int T; |
| 35 |
T i = 3; |
| 36 |
std::promise<T> p; |
| 37 |
std::future<T> f = p.get_future(); |
| 38 |
p.set_value(i); |
| 39 |
++i; |
| 40 |
assert(f.get() == 3); |
| 41 |
#ifndef TEST_HAS_NO_EXCEPTIONS |
| 42 |
--i; |
| 43 |
try |
| 44 |
{ |
| 45 |
p.set_value(i); |
| 46 |
assert(false); |
| 47 |
} |
| 48 |
catch (const std::future_error& e) |
| 49 |
{ |
| 50 |
assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied)); |
| 51 |
} |
| 52 |
#endif |
| 53 |
} |
| 54 |
{ |
| 55 |
typedef A T; |
| 56 |
T i; |
| 57 |
std::promise<T> p; |
| 58 |
std::future<T> f = p.get_future(); |
| 59 |
#ifndef TEST_HAS_NO_EXCEPTIONS |
| 60 |
try |
| 61 |
{ |
| 62 |
p.set_value(i); |
| 63 |
assert(false); |
| 64 |
} |
| 65 |
catch (int j) |
| 66 |
{ |
| 67 |
assert(j == 10); |
| 68 |
} |
| 69 |
#endif |
| 70 |
} |
| 71 |
|
| 72 |
return 0; |
| 73 |
} |