2 // { dg-options "-pthread" }
3 // { dg-require-effective-target c++11 }
4 // { dg-require-effective-target pthread }
5 // { dg-require-cstdint "" }
6 // { dg-require-gthreads "" }
8 // Copyright (C) 2014-2018 Free Software Foundation, Inc.
10 // This file is part of the GNU ISO C++ Library. This library is free
11 // software; you can redistribute it and/or modify it under the
12 // terms of the GNU General Public License as published by the
13 // Free Software Foundation; either version 3, or (at your option)
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License along
22 // with this library; see the file COPYING3. If not see
23 // <http://www.gnu.org/licenses/>.
25 // Test set_value_at_thread_exit error conditions
28 #include <testsuite_hooks.h>
36 p1
.set_value_at_thread_exit(2);
39 catch (std::future_error
& e
)
41 VERIFY( e
.code() == std::future_errc::promise_already_satisfied
);
45 p1
.set_exception_at_thread_exit(std::make_exception_ptr(3));
48 catch (std::future_error
& e
)
50 VERIFY( e
.code() == std::future_errc::promise_already_satisfied
);
53 std::promise
<int> p2(std::move(p1
));
56 p1
.set_value_at_thread_exit(2);
59 catch (std::future_error
& e
)
61 VERIFY( e
.code() == std::future_errc::no_state
);
65 p1
.set_exception_at_thread_exit(std::make_exception_ptr(3));
68 catch (std::future_error
& e
)
70 VERIFY( e
.code() == std::future_errc::no_state
);
76 std::promise
<int&> p1
;
81 p1
.set_value_at_thread_exit(i
);
84 catch (std::future_error
& e
)
86 VERIFY( e
.code() == std::future_errc::promise_already_satisfied
);
90 p1
.set_exception_at_thread_exit(std::make_exception_ptr(3));
93 catch (std::future_error
& e
)
95 VERIFY( e
.code() == std::future_errc::promise_already_satisfied
);
98 std::promise
<int&> p2(std::move(p1
));
102 p1
.set_value_at_thread_exit(i
);
105 catch (std::future_error
& e
)
107 VERIFY( e
.code() == std::future_errc::no_state
);
111 p1
.set_exception_at_thread_exit(std::make_exception_ptr(3));
114 catch (std::future_error
& e
)
116 VERIFY( e
.code() == std::future_errc::no_state
);
122 std::promise
<void> p1
;
126 p1
.set_value_at_thread_exit();
129 catch (std::future_error
& e
)
131 VERIFY( e
.code() == std::future_errc::promise_already_satisfied
);
135 p1
.set_exception_at_thread_exit(std::make_exception_ptr(3));
138 catch (std::future_error
& e
)
140 VERIFY( e
.code() == std::future_errc::promise_already_satisfied
);
143 std::promise
<void> p2(std::move(p1
));
145 p1
.set_value_at_thread_exit();
148 catch (std::future_error
& e
)
150 VERIFY( e
.code() == std::future_errc::no_state
);
154 p1
.set_exception_at_thread_exit(std::make_exception_ptr(3));
157 catch (std::future_error
& e
)
159 VERIFY( e
.code() == std::future_errc::no_state
);