| 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 operator&=(integral-type) const noexcept; |
| 12 |
|
| 13 |
#include <atomic> |
| 14 |
#include <cassert> |
| 15 |
#include <concepts> |
| 16 |
#include <type_traits> |
| 17 |
|
| 18 |
#include "atomic_helpers.h" |
| 19 |
#include "test_macros.h" |
| 20 |
|
| 21 |
template <typename T> |
| 22 |
concept has_bitwise_and_assign = requires { std::declval<T const>() &= std::declval<T>(); }; |
| 23 |
|
| 24 |
template <typename T> |
| 25 |
struct TestDoesNotHaveBitwiseAndAssign { |
| 26 |
void operator()() const { static_assert(!has_bitwise_and_assign<std::atomic_ref<T>>); } |
| 27 |
}; |
| 28 |
|
| 29 |
template <typename T> |
| 30 |
struct TestBitwiseAndAssign { |
| 31 |
void operator()() const { |
| 32 |
static_assert(std::is_integral_v<T>); |
| 33 |
|
| 34 |
T x(T(1)); |
| 35 |
std::atomic_ref<T> const a(x); |
| 36 |
|
| 37 |
std::same_as<T> decltype(auto) y = (a &= T(1)); |
| 38 |
assert(y == T(1)); |
| 39 |
assert(x == T(1)); |
| 40 |
ASSERT_NOEXCEPT(a &= T(0)); |
| 41 |
|
| 42 |
y = (a &= T(2)); |
| 43 |
assert(y == T(0)); |
| 44 |
assert(x == T(0)); |
| 45 |
} |
| 46 |
}; |
| 47 |
|
| 48 |
int main(int, char**) { |
| 49 |
TestEachIntegralType<TestBitwiseAndAssign>()(); |
| 50 |
|
| 51 |
TestEachFloatingPointType<TestDoesNotHaveBitwiseAndAssign>()(); |
| 52 |
|
| 53 |
TestEachPointerType<TestDoesNotHaveBitwiseAndAssign>()(); |
| 54 |
|
| 55 |
TestDoesNotHaveBitwiseAndAssign<bool>()(); |
| 56 |
TestDoesNotHaveBitwiseAndAssign<UserAtomicType>()(); |
| 57 |
TestDoesNotHaveBitwiseAndAssign<LargeUserAtomicType>()(); |
| 58 |
|
| 59 |
return 0; |
| 60 |
} |