Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / thread / thread.jthread / get_stop_token.pass.cpp
blob070761e0a3ab883c4d3c89089bd118316dff9945
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 // [[nodiscard]] stop_token get_stop_token() const noexcept;
16 #include <cassert>
17 #include <concepts>
18 #include <stop_token>
19 #include <thread>
20 #include <type_traits>
21 #include <utility>
23 #include "make_test_thread.h"
24 #include "test_macros.h"
26 static_assert(noexcept(std::declval<const std::jthread&>().get_stop_token()));
28 int main(int, char**) {
29 // Represents a thread
31 std::jthread jt = support::make_test_jthread([] {});
32 auto ss = jt.get_stop_source();
33 std::same_as<std::stop_token> decltype(auto) st = std::as_const(jt).get_stop_token();
35 assert(st.stop_possible());
36 assert(!st.stop_requested());
37 ss.request_stop();
38 assert(st.stop_requested());
41 // Does not represent a thread
43 const std::jthread jt{};
44 std::same_as<std::stop_token> decltype(auto) st = jt.get_stop_token();
46 assert(!st.stop_possible());
49 return 0;