1*b77e50e6SHui //===----------------------------------------------------------------------===// 2*b77e50e6SHui // 3*b77e50e6SHui // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*b77e50e6SHui // See https://llvm.org/LICENSE.txt for license information. 5*b77e50e6SHui // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*b77e50e6SHui // 7*b77e50e6SHui //===----------------------------------------------------------------------===// 8*b77e50e6SHui // 9*b77e50e6SHui // UNSUPPORTED: no-threads 10*b77e50e6SHui // UNSUPPORTED: c++03, c++11, c++14, c++17 11*b77e50e6SHui // XFAIL: availability-synchronization_library-missing 12*b77e50e6SHui 13*b77e50e6SHui // stop_source(const stop_source&) noexcept; 14*b77e50e6SHui 15*b77e50e6SHui #include <cassert> 16*b77e50e6SHui #include <optional> 17*b77e50e6SHui #include <stop_token> 18*b77e50e6SHui #include <type_traits> 19*b77e50e6SHui 20*b77e50e6SHui #include "test_macros.h" 21*b77e50e6SHui 22*b77e50e6SHui static_assert(std::is_nothrow_copy_constructible_v<std::stop_source>); 23*b77e50e6SHui 24*b77e50e6SHui int main(int, char**) { 25*b77e50e6SHui { 26*b77e50e6SHui std::stop_source source; 27*b77e50e6SHui std::stop_source copy{source}; 28*b77e50e6SHui 29*b77e50e6SHui assert(source == copy); 30*b77e50e6SHui 31*b77e50e6SHui assert(source.stop_possible()); 32*b77e50e6SHui assert(!source.stop_requested()); 33*b77e50e6SHui 34*b77e50e6SHui assert(copy.stop_possible()); 35*b77e50e6SHui assert(!copy.stop_requested()); 36*b77e50e6SHui 37*b77e50e6SHui source.request_stop(); 38*b77e50e6SHui assert(source.stop_possible()); 39*b77e50e6SHui assert(source.stop_requested()); 40*b77e50e6SHui 41*b77e50e6SHui assert(copy.stop_possible()); 42*b77e50e6SHui assert(copy.stop_requested()); 43*b77e50e6SHui } 44*b77e50e6SHui 45*b77e50e6SHui // source counter incremented 46*b77e50e6SHui { 47*b77e50e6SHui std::optional<std::stop_source> source(std::in_place); 48*b77e50e6SHui auto st = source->get_token(); 49*b77e50e6SHui assert(st.stop_possible()); 50*b77e50e6SHui 51*b77e50e6SHui std::optional<std::stop_source> copy{source}; 52*b77e50e6SHui source.reset(); 53*b77e50e6SHui 54*b77e50e6SHui assert(st.stop_possible()); 55*b77e50e6SHui 56*b77e50e6SHui copy.reset(); 57*b77e50e6SHui assert(!st.stop_possible()); 58*b77e50e6SHui } 59*b77e50e6SHui 60*b77e50e6SHui // copy from empty 61*b77e50e6SHui { 62*b77e50e6SHui std::stop_source ss1{std::nostopstate}; 63*b77e50e6SHui std::stop_source copy{ss1}; 64*b77e50e6SHui assert(!copy.stop_possible()); 65*b77e50e6SHui } 66*b77e50e6SHui 67*b77e50e6SHui return 0; 68*b77e50e6SHui } 69