1 // 2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 3 // See https://llvm.org/LICENSE.txt for license information. 4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 // 6 //===----------------------------------------------------------------------===// 7 8 // UNSUPPORTED: c++03, c++11, c++14, c++17 9 // XFAIL: !has-64-bit-atomics 10 11 // integral-type fetch_xor(integral-type, memory_order = memory_order::seq_cst) const noexcept; 12 13 #include <atomic> 14 #include <cassert> 15 #include <concepts> 16 #include <type_traits> 17 #include <utility> 18 19 #include "atomic_helpers.h" 20 #include "test_macros.h" 21 22 template <typename T> 23 concept has_fetch_xor = requires { 24 std::declval<T const>().fetch_xor(std::declval<T>()); 25 std::declval<T const>().fetch_xor(std::declval<T>(), std::declval<std::memory_order>()); 26 }; 27 28 template <typename T> 29 struct TestDoesNotHaveFetchXor { 30 void operator()() const { static_assert(!has_fetch_xor<std::atomic_ref<T>>); } 31 }; 32 33 template <typename T> 34 struct TestFetchXor { 35 void operator()() const { 36 static_assert(std::is_integral_v<T>); 37 38 T x(T(1)); 39 std::atomic_ref<T> const a(x); 40 41 { 42 std::same_as<T> decltype(auto) y = a.fetch_xor(T(2)); 43 assert(y == T(1)); 44 assert(x == T(3)); 45 ASSERT_NOEXCEPT(a.fetch_xor(T(0))); 46 } 47 48 { 49 std::same_as<T> decltype(auto) y = a.fetch_xor(T(2), std::memory_order_relaxed); 50 assert(y == T(3)); 51 assert(x == T(1)); 52 ASSERT_NOEXCEPT(a.fetch_xor(T(0), std::memory_order_relaxed)); 53 } 54 } 55 }; 56 57 int main(int, char**) { 58 TestEachIntegralType<TestFetchXor>()(); 59 60 TestEachFloatingPointType<TestDoesNotHaveFetchXor>()(); 61 62 TestEachPointerType<TestDoesNotHaveFetchXor>()(); 63 64 TestDoesNotHaveFetchXor<bool>()(); 65 TestDoesNotHaveFetchXor<UserAtomicType>()(); 66 TestDoesNotHaveFetchXor<LargeUserAtomicType>()(); 67 68 return 0; 69 } 70