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

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 2 08:59:18 PDT 2023


================
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// 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: c++03, c++11, c++14, c++17
+
+// constexpr atomic() noexcept;
+// constexpr atomic(floating-point-type) noexcept;
+
+#include <atomic>
+#include <cassert>
+#include <concepts>
+
+#include "test_macros.h"
+
+template <class T>
+void test() {
+  // constexpr atomic() noexcept;
+  {
+    constexpr std::atomic<T> a = {};
+    assert(a.load() == T(0));
+  }
+
+  // constexpr atomic(floating-point-type) noexcept;
+  {
+    constexpr std::atomic<T> a = T(5.2);
+    assert(a.load() == T(5.2));
+  }
+}
+
+int main(int, char**) {
+  test<float>();
----------------
ldionne wrote:

The way we check for constexpr-ness is generally to have a `constexpr bool test()` function and call it both in constexpr and non-constexpr mode. That way we check that it works at runtime as well.

Since only the constructor is `constexpr`, the `assert` would have to be hidden behind `if (!TEST_IS_CONSTANT_EVALUATED)`.

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


More information about the libcxx-commits mailing list