[libcxx-commits] [libcxx] [libcxx] P0718R2: Implementation of std::atomic<shared_ptr<T>> and std::atomic<weak_ptr<T>> (PR #194215)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Sat May 2 04:55:29 PDT 2026


================
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++20
+// UNSUPPORTED: no-threads
+
+// static constexpr bool is_always_lock_free;
+// bool is_lock_free() const noexcept;
+
+#include <atomic>
+#include <memory>
+
+#include "../atomic_smart_ptr_test_types.h"
+#include "test_macros.h"
+
+template <class T>
+void check() {
+  using A = std::atomic<std::shared_ptr<T>>;
+
+  static_assert(std::same_as<decltype(A::is_always_lock_free), const bool>);
+  static_assert(!static_cast<bool>(A::is_always_lock_free));
+
+  const A asp;
+  std::same_as<bool> decltype(auto) lf = asp.is_lock_free();
+  (void)lf;
+  ASSERT_NOEXCEPT(A::is_always_lock_free);
+  ASSERT_NOEXCEPT(asp.is_lock_free());
----------------
H-G-Hristov wrote:

Why is this test `*.compile.pass.cpp` instead of a runtime test `.pass.cpp`?

Have you checked the documentation when to use `.compile.pass.cpp`, `.verify.pass.cpp`, etc. ? Also I think compile and verify tests don't need `main()`.

I think that since C++20  
   `std::same_as<bool> decltype(auto) lf = asp.is_lock_free();` 
and 
   `static_assert(noexcept(asp.is_lock_free());`
   
are the preferred patterns to test the return type and `noexcept`. 
Anyway pick one or the other and use it throughout consistently : 
`ASSERT_NOEXCEPT` or `static_assert(noxcept(...));` 
and
 `ASSERT_SAME_TYPE` or` std::same_as<..> decltype(auto) .. = ;`


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


More information about the libcxx-commits mailing list