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: libcpp-has-no-threads
10 // UNSUPPORTED: c++03
11 
12 // <future>
13 
14 // class future<R>
15 
16 // shared_future<R> share() &&;
17 
18 #include <future>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 
main(int,char **)23 int main(int, char**)
24 {
25     {
26         typedef int T;
27         std::promise<T> p;
28         std::future<T> f0 = p.get_future();
29         static_assert( noexcept(f0.share()), "");
30         std::shared_future<T> f = f0.share();
31         assert(!f0.valid());
32         assert(f.valid());
33     }
34     {
35         typedef int T;
36         std::future<T> f0;
37         static_assert( noexcept(f0.share()), "");
38         std::shared_future<T> f = f0.share();
39         assert(!f0.valid());
40         assert(!f.valid());
41     }
42     {
43         typedef int& T;
44         std::promise<T> p;
45         std::future<T> f0 = p.get_future();
46         static_assert( noexcept(f0.share()), "");
47         std::shared_future<T> f = f0.share();
48         assert(!f0.valid());
49         assert(f.valid());
50     }
51     {
52         typedef int& T;
53         std::future<T> f0;
54         static_assert( noexcept(f0.share()), "");
55         std::shared_future<T> f = f0.share();
56         assert(!f0.valid());
57         assert(!f.valid());
58     }
59     {
60         typedef void T;
61         std::promise<T> p;
62         std::future<T> f0 = p.get_future();
63         static_assert( noexcept(f0.share()), "");
64         std::shared_future<T> f = f0.share();
65         assert(!f0.valid());
66         assert(f.valid());
67     }
68     {
69         typedef void T;
70         std::future<T> f0;
71         static_assert( noexcept(f0.share()), "");
72         std::shared_future<T> f = f0.share();
73         assert(!f0.valid());
74         assert(!f.valid());
75     }
76 
77   return 0;
78 }
79