1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // XFAIL: availability-synchronization_library-missing
13 // jthread(jthread&& x) noexcept;
18 #include <type_traits>
21 #include "make_test_thread.h"
22 #include "test_macros.h"
24 static_assert(std::is_nothrow_move_constructible_v
<std::jthread
>);
26 int main(int, char**) {
28 // x.get_id() == id() and get_id() returns the value of x.get_id() prior
29 // to the start of construction.
30 std::jthread j1
= support::make_test_jthread([] {});
31 auto id1
= j1
.get_id();
33 std::jthread
j2(std::move(j1
));
34 assert(j1
.get_id() == std::jthread::id());
35 assert(j2
.get_id() == id1
);
39 // ssource has the value of x.ssource prior to the start of construction
40 // and x.ssource.stop_possible() is false.
41 std::jthread j1
= support::make_test_jthread([] {});
42 auto ss1
= j1
.get_stop_source();
44 std::jthread
j2(std::move(j1
));
45 assert(ss1
== j2
.get_stop_source());
46 assert(!j1
.get_stop_source().stop_possible());
47 assert(j2
.get_stop_source().stop_possible());