blob: 6673f6307579122a6069791896d6f259b69b8648 [file] [log] [blame]
Howard Hinnantf39daa82010-08-28 21:01:06 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantf39daa82010-08-28 21:01:06 +00007//
8//===----------------------------------------------------------------------===//
Jonathan Roelofs8d86b2e2014-09-05 19:45:05 +00009//
10// UNSUPPORTED: libcpp-has-no-threads
Howard Hinnantf39daa82010-08-28 21:01:06 +000011
12// <future>
13
14// class promise<R>
15
16// void promise::set_value(const R& r);
17
18#include <future>
19#include <cassert>
20
21struct A
22{
23 A() {}
24 A(const A&) {throw 10;}
25};
26
27int main()
28{
29 {
30 typedef int T;
31 T i = 3;
32 std::promise<T> p;
33 std::future<T> f = p.get_future();
34 p.set_value(i);
35 ++i;
36 assert(f.get() == 3);
37 --i;
38 try
39 {
40 p.set_value(i);
41 assert(false);
42 }
43 catch (const std::future_error& e)
44 {
45 assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
46 }
47 }
48 {
49 typedef A T;
50 T i;
51 std::promise<T> p;
52 std::future<T> f = p.get_future();
53 try
54 {
55 p.set_value(i);
56 assert(false);
57 }
58 catch (int j)
59 {
60 assert(j == 10);
61 }
62 }
63}