Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jonathan Roelofs | 8d86b2e | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 9 | // |
| 10 | // UNSUPPORTED: libcpp-has-no-threads |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 11 | |
| 12 | // <future> |
| 13 | |
| 14 | // class promise<R> |
| 15 | |
| 16 | // void set_exception(exception_ptr p); |
| 17 | |
| 18 | #include <future> |
| 19 | #include <cassert> |
| 20 | |
| 21 | int main() |
| 22 | { |
| 23 | { |
| 24 | typedef int T; |
| 25 | std::promise<T> p; |
| 26 | std::future<T> f = p.get_future(); |
| 27 | p.set_exception(std::make_exception_ptr(3)); |
| 28 | try |
| 29 | { |
| 30 | f.get(); |
| 31 | assert(false); |
| 32 | } |
| 33 | catch (int i) |
| 34 | { |
| 35 | assert(i == 3); |
| 36 | } |
| 37 | try |
| 38 | { |
| 39 | p.set_exception(std::make_exception_ptr(3)); |
| 40 | assert(false); |
| 41 | } |
| 42 | catch (const std::future_error& e) |
| 43 | { |
| 44 | assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied)); |
| 45 | } |
| 46 | } |
| 47 | } |