[libcxx-commits] [libcxx] [libc++][In progress] Floating Point Atomic (PR #67799)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 13 11:06:37 PDT 2023


================
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: no-threads
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+//  floating-point-type operator=(floating-point-type) volatile noexcept;
+//  floating-point-type operator=(floating-point-type) noexcept;
+
+#include <atomic>
+#include <cassert>
+#include <concepts>
+
+#include "test_helper.h"
+#include "test_macros.h"
+
+template <class T>
+concept HasVolatileAssign = requires(volatile std::atomic<T> a, T t) { a = t; };
+
+template <class T, template <class> class MaybeVolatile = std::type_identity_t>
+void testImpl() {
+  static_assert(HasVolatileAssign<T> == std::atomic<T>::is_always_lock_free);
+
+  static_assert(noexcept(std::declval<MaybeVolatile<std::atomic<T>>&>() = (T(0))));
+
+  // assignment
+  {
+    MaybeVolatile<std::atomic<T>> a(3.1);
+    std::same_as<T> decltype(auto) r = (a = T(1.2));
+    assert(a.load() == T(1.2));
+    assert(r == T(1.2));
+  }
+
+  // memory_order::seq_cst
+  {
----------------
ldionne wrote:

Instead of `UNSUPPORTED: no-threads`, I would consider using `#ifndef TEST_HAS_NO_THREADS` just to guard the bit of the test that actually requires threads. That way, the tests would partly work on platforms that support atomics but not threads (many embedded).

https://github.com/llvm/llvm-project/pull/67799


More information about the libcxx-commits mailing list