brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 9b2f904 Raw
52 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// XFAIL: !has-1024-bit-atomics11 12// T operator=(T) const noexcept;13 14#include <atomic>15#include <cassert>16#include <concepts>17#include <type_traits>18 19#include "atomic_helpers.h"20#include "test_helper.h"21#include "test_macros.h"22 23template <typename T>24struct TestAssign {25  void operator()() const {26    {27      T x(T(1));28      std::atomic_ref<T> const a(x);29 30      std::same_as<T> decltype(auto) y = (a = T(2));31      assert(y == T(2));32      assert(x == T(2));33 34      ASSERT_NOEXCEPT(a = T(0));35      static_assert(std::is_nothrow_assignable_v<std::atomic_ref<T>, T>);36 37      static_assert(!std::is_copy_assignable_v<std::atomic_ref<T>>);38    }39 40    {41      auto assign = [](std::atomic_ref<T> const& y, T, T new_val) { y = new_val; };42      auto load   = [](std::atomic_ref<T> const& y) { return y.load(); };43      test_seq_cst<T>(assign, load);44    }45  }46};47 48int main(int, char**) {49  TestEachAtomicType<TestAssign>()();50  return 0;51}52