1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <future>
11
12// class promise<R>
13
14// void promise::set_value(R&& r);
15
16#include <future>
17#include <memory>
18#include <cassert>
19
20#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
21
22struct A
23{
24    A() {}
25    A(const A&) = delete;
26    A(A&&) {throw 9;}
27};
28
29#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
30
31int main()
32{
33#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
34    {
35        typedef std::unique_ptr<int> T;
36        T i(new int(3));
37        std::promise<T> p;
38        std::future<T> f = p.get_future();
39        p.set_value(std::move(i));
40        assert(*f.get() == 3);
41        try
42        {
43            p.set_value(std::move(i));
44            assert(false);
45        }
46        catch (const std::future_error& e)
47        {
48            assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
49        }
50    }
51    {
52        typedef A T;
53        T i;
54        std::promise<T> p;
55        std::future<T> f = p.get_future();
56        try
57        {
58            p.set_value(std::move(i));
59            assert(false);
60        }
61        catch (int j)
62        {
63            assert(j == 9);
64        }
65    }
66#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
67}
68