62 lines · cpp
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-exception5//6//===----------------------------------------------------------------------===//7 8// UNSUPPORTED: c++03, c++11, c++14, c++179// XFAIL: !has-64-bit-atomics10 11// integral-type operator&=(integral-type) 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 22template <typename T>23concept has_bitwise_and_assign = requires { std::declval<T const>() &= std::declval<T>(); };24 25template <typename T>26struct TestDoesNotHaveBitwiseAndAssign {27 void operator()() const { static_assert(!has_bitwise_and_assign<std::atomic_ref<T>>); }28};29 30template <typename T>31struct TestBitwiseAndAssign {32 void operator()() const {33 static_assert(std::is_integral_v<T>);34 35 T x(T(1));36 std::atomic_ref<T> const a(x);37 38 std::same_as<T> decltype(auto) y = (a &= T(1));39 assert(y == T(1));40 assert(x == T(1));41 ASSERT_NOEXCEPT(a &= T(0));42 43 y = (a &= T(2));44 assert(y == T(0));45 assert(x == T(0));46 }47};48 49int main(int, char**) {50 TestEachIntegralType<TestBitwiseAndAssign>()();51 52 TestEachFloatingPointType<TestDoesNotHaveBitwiseAndAssign>()();53 54 TestEachPointerType<TestDoesNotHaveBitwiseAndAssign>()();55 56 TestDoesNotHaveBitwiseAndAssign<bool>()();57 TestDoesNotHaveBitwiseAndAssign<UserAtomicType>()();58 TestDoesNotHaveBitwiseAndAssign<LargeUserAtomicType>()();59 60 return 0;61}62