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: c++03, c++11, c++14, c++17 11 // XFAIL: availability-synchronization_library-missing 12 13 // stop_source& operator=(const stop_source& rhs) noexcept; 14 15 #include <cassert> 16 #include <concepts> 17 #include <stop_token> 18 #include <type_traits> 19 20 #include "test_macros.h" 21 22 static_assert(std::is_nothrow_copy_assignable_v<std::stop_source>); 23 24 int main(int, char**) { 25 // have two different states 26 { 27 std::stop_source ss1; 28 std::stop_source ss2; 29 30 assert(ss1 != ss2); 31 32 ss2.request_stop(); 33 34 assert(!ss1.stop_requested()); 35 assert(ss2.stop_requested()); 36 37 std::same_as<std::stop_source&> decltype(auto) ref = ss1 = ss2; 38 assert(&ref == &ss1); 39 40 assert(ss1 == ss2); 41 assert(ss1.stop_requested()); 42 assert(ss2.stop_requested()); 43 } 44 45 // this has no state 46 { 47 std::stop_source ss1{std::nostopstate}; 48 std::stop_source ss2; 49 50 assert(ss1 != ss2); 51 52 ss2.request_stop(); 53 54 assert(!ss1.stop_requested()); 55 assert(!ss1.stop_possible()); 56 assert(ss2.stop_requested()); 57 assert(ss2.stop_possible()); 58 59 std::same_as<std::stop_source&> decltype(auto) ref = ss1 = ss2; 60 assert(&ref == &ss1); 61 62 assert(ss1 == ss2); 63 assert(ss1.stop_requested()); 64 assert(ss1.stop_possible()); 65 assert(ss2.stop_requested()); 66 assert(ss2.stop_possible()); 67 } 68 69 // other has no state 70 { 71 std::stop_source ss1; 72 std::stop_source ss2{std::nostopstate}; 73 74 assert(ss1 != ss2); 75 76 ss1.request_stop(); 77 78 assert(ss1.stop_requested()); 79 assert(ss1.stop_possible()); 80 assert(!ss2.stop_requested()); 81 assert(!ss2.stop_possible()); 82 83 std::same_as<std::stop_source&> decltype(auto) ref = ss1 = ss2; 84 assert(&ref == &ss1); 85 86 assert(ss1 == ss2); 87 assert(!ss1.stop_requested()); 88 assert(!ss1.stop_possible()); 89 assert(!ss2.stop_requested()); 90 assert(!ss2.stop_possible()); 91 } 92 93 // both no state 94 { 95 std::stop_source ss1{std::nostopstate}; 96 std::stop_source ss2{std::nostopstate}; 97 98 assert(ss1 == ss2); 99 100 assert(!ss1.stop_requested()); 101 assert(!ss1.stop_possible()); 102 assert(!ss2.stop_requested()); 103 assert(!ss2.stop_possible()); 104 105 std::same_as<std::stop_source&> decltype(auto) ref = ss1 = ss2; 106 assert(&ref == &ss1); 107 108 assert(ss1 == ss2); 109 assert(!ss1.stop_requested()); 110 assert(!ss1.stop_possible()); 111 assert(!ss2.stop_requested()); 112 assert(!ss2.stop_possible()); 113 } 114 115 // self assignment 116 { 117 std::stop_source ss; 118 auto& self = ss; 119 120 assert(!ss.stop_requested()); 121 122 std::same_as<std::stop_source&> decltype(auto) ref = ss = self; 123 assert(&ref == &ss); 124 125 assert(!ss.stop_requested()); 126 127 ss.request_stop(); 128 assert(ss.stop_requested()); 129 } 130 131 return 0; 132 } 133