libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

set_exception.pass.cpp (1173B)


      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-no-exceptions
     11 // UNSUPPORTED: libcpp-has-no-threads
     12 // UNSUPPORTED: c++98, c++03
     13 
     14 // <future>
     15 
     16 // class promise<R>
     17 
     18 // void set_exception(exception_ptr p);
     19 
     20 #include <future>
     21 #include <cassert>
     22 
     23 int main()
     24 {
     25     {
     26         typedef int T;
     27         std::promise<T> p;
     28         std::future<T> f = p.get_future();
     29         p.set_exception(std::make_exception_ptr(3));
     30         try
     31         {
     32             f.get();
     33             assert(false);
     34         }
     35         catch (int i)
     36         {
     37             assert(i == 3);
     38         }
     39         try
     40         {
     41             p.set_exception(std::make_exception_ptr(3));
     42             assert(false);
     43         }
     44         catch (const std::future_error& e)
     45         {
     46             assert(e.code() == make_error_code(std::future_errc::promise_already_satisfied));
     47         }
     48     }
     49 }