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