Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / thread / thread.jthread / cons.move.pass.cpp
blobc3c04467703c96e4549b5f2e5e247fdcd3a6dc57
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: libcpp-has-no-experimental-stop_token
11 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // XFAIL: availability-synchronization_library-missing
14 // jthread(jthread&& x) noexcept;
16 #include <cassert>
17 #include <stop_token>
18 #include <thread>
19 #include <type_traits>
20 #include <utility>
22 #include "make_test_thread.h"
23 #include "test_macros.h"
25 static_assert(std::is_nothrow_move_constructible_v<std::jthread>);
27 int main(int, char**) {
29 // x.get_id() == id() and get_id() returns the value of x.get_id() prior
30 // to the start of construction.
31 std::jthread j1 = support::make_test_jthread([] {});
32 auto id1 = j1.get_id();
34 std::jthread j2(std::move(j1));
35 assert(j1.get_id() == std::jthread::id());
36 assert(j2.get_id() == id1);
40 // ssource has the value of x.ssource prior to the start of construction
41 // and x.ssource.stop_possible() is false.
42 std::jthread j1 = support::make_test_jthread([] {});
43 auto ss1 = j1.get_stop_source();
45 std::jthread j2(std::move(j1));
46 assert(ss1 == j2.get_stop_source());
47 assert(!j1.get_stop_source().stop_possible());
48 assert(j2.get_stop_source().stop_possible());
51 return 0;