Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / thread / futures / futures.task / futures.task.members / dtor.pass.cpp
blob606dccc345dbf3b11e2f12d86e6cd52835fc5186
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03
12 // <future>
14 // class packaged_task<R(ArgTypes...)>
16 // ~packaged_task();
18 #include <future>
19 #include <cassert>
21 #include "make_test_thread.h"
22 #include "test_macros.h"
24 class A
26 long data_;
28 public:
29 explicit A(long i) : data_(i) {}
31 long operator()(long i, long j) const {return data_ + i + j;}
34 void func(std::packaged_task<double(int, char)>)
38 void func2(std::packaged_task<double(int, char)> p) { p(3, 97); }
40 int main(int, char**)
42 #ifndef TEST_HAS_NO_EXCEPTIONS
44 std::packaged_task<double(int, char)> p(A(5));
45 std::future<double> f = p.get_future();
46 support::make_test_thread(func, std::move(p)).detach();
47 try
49 double i = f.get();
50 ((void)i); // Prevent unused warning
51 assert(false);
53 catch (const std::future_error& e)
55 assert(e.code() == make_error_code(std::future_errc::broken_promise));
58 #endif
60 std::packaged_task<double(int, char)> p(A(5));
61 std::future<double> f = p.get_future();
62 support::make_test_thread(func2, std::move(p)).detach();
63 assert(f.get() == 105.0);
66 return 0;