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 // UNSUPPORTED: libcpp-has-no-threads 11 12 // <future> 13 14 // class promise<R> 15 16 // void promise::set_value(R&& r); 17 18 #include <future> 19 #include <memory> 20 #include <cassert> 21 22 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 23 24 struct A 25 { 26 A() {} 27 A(const A&) = delete; 28 A(A&&) {throw 9;} 29 }; 30 31 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 32 33 int main() 34 { 35 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 36 { 37 typedef std::unique_ptr<int> T; 38 T i(new int(3)); 39 std::promise<T> p; 40 std::future<T> f = p.get_future(); 41 p.set_value(std::move(i)); 42 assert(*f.get() == 3); 43 try 44 { 45 p.set_value(std::move(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 } 53 { 54 typedef A T; 55 T i; 56 std::promise<T> p; 57 std::future<T> f = p.get_future(); 58 try 59 { 60 p.set_value(std::move(i)); 61 assert(false); 62 } 63 catch (int j) 64 { 65 assert(j == 9); 66 } 67 } 68 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 69 } 70