68 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310// UNSUPPORTED: no-threads, no-exceptions11 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#include "test_macros.h"23 24struct A25{26 A() {}27 A(const A&) = delete;28 A(A&&) {throw 9;}29};30 31int main(int, char**)32{33 {34 typedef std::unique_ptr<int> T;35 T i(new int(3));36 std::promise<T> p;37 std::future<T> f = p.get_future();38 p.set_value(std::move(i));39 assert(*f.get() == 3);40 try41 {42 p.set_value(std::move(i));43 assert(false);44 }45 catch (const std::future_error& e)46 {47 assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));48 }49 }50 {51 typedef A T;52 T i;53 std::promise<T> p;54 std::future<T> f = p.get_future();55 try56 {57 p.set_value(std::move(i));58 assert(false);59 }60 catch (int j)61 {62 assert(j == 9);63 }64 }65 66 return 0;67}68