1695138caSHui //===----------------------------------------------------------------------===// 2695138caSHui // 3695138caSHui // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4695138caSHui // See https://llvm.org/LICENSE.txt for license information. 5695138caSHui // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6695138caSHui // 7695138caSHui //===----------------------------------------------------------------------===// 8695138caSHui // 9695138caSHui // UNSUPPORTED: no-threads 10695138caSHui // UNSUPPORTED: c++03, c++11, c++14, c++17 11695138caSHui // XFAIL: availability-synchronization_library-missing 12695138caSHui 13695138caSHui // [[nodiscard]] id get_id() const noexcept; 14695138caSHui 15695138caSHui #include <cassert> 16695138caSHui #include <concepts> 17695138caSHui #include <thread> 18695138caSHui #include <type_traits> 19695138caSHui 20*475e1543SLouis Dionne #include "make_test_thread.h" 21695138caSHui #include "test_macros.h" 22695138caSHui 23695138caSHui static_assert(noexcept(std::declval<const std::jthread&>().get_id())); 24695138caSHui 25695138caSHui int main(int, char**) { 26695138caSHui // Does not represent a thread 27695138caSHui { 28695138caSHui const std::jthread jt; 29695138caSHui std::same_as<std::jthread::id> decltype(auto) result = jt.get_id(); 30695138caSHui assert(result == std::jthread::id()); 31695138caSHui } 32695138caSHui 33695138caSHui // Represents a thread 34695138caSHui { 35*475e1543SLouis Dionne const std::jthread jt = support::make_test_jthread([] {}); 36695138caSHui std::same_as<std::jthread::id> decltype(auto) result = jt.get_id(); 37695138caSHui assert(result != std::jthread::id()); 38695138caSHui } 39695138caSHui 40695138caSHui return 0; 41695138caSHui } 42