brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · bc6bc26 Raw
53 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: no-exceptions10// UNSUPPORTED: no-threads11// UNSUPPORTED: c++0312 13// <future>14 15// class promise<R>16 17// void set_exception(exception_ptr p);18 19#include <future>20#include <cassert>21 22#include "test_macros.h"23 24int main(int, char**)25{26    {27        typedef int T;28        std::promise<T> p;29        std::future<T> f = p.get_future();30        p.set_exception(std::make_exception_ptr(3));31        try32        {33            f.get();34            assert(false);35        }36        catch (int i)37        {38            assert(i == 3);39        }40        try41        {42            p.set_exception(std::make_exception_ptr(3));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  return 0;52}53