1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// UNSUPPORTED: c++03, c++11, c++14, c++17
9// XFAIL: !has-64-bit-atomics
10
11// static constexpr bool is_always_lock_free = implementation-defined;
12// bool is_lock_free() const volatile noexcept;
13// bool is_lock_free() const noexcept;
14
15#include <atomic>
16#include <cassert>
17#include <concepts>
18#include <type_traits>
19
20#include "test_macros.h"
21
22template <class T>
23concept isLockFreeNoexcept = requires(T t) {
24 { t.is_lock_free() } noexcept;
25};
26
27template <class T>
28void test() {
29 static_assert(isLockFreeNoexcept<const std::atomic<T>&>);
30 static_assert(isLockFreeNoexcept<const volatile std::atomic<T>&>);
31
32 // static constexpr bool is_always_lock_free = implementation-defined;
33 { [[maybe_unused]] constexpr std::same_as<const bool> decltype(auto) r = std::atomic<T>::is_always_lock_free; }
34
35 // bool is_lock_free() const volatile noexcept;
36 {
37 const volatile std::atomic<T> a;
38 std::same_as<bool> decltype(auto) r = a.is_lock_free();
39 if (std::atomic<T>::is_always_lock_free) {
40 assert(r);
41 }
42 }
43
44 // bool is_lock_free() const noexcept;
45 {
46 const std::atomic<T> a;
47 std::same_as<bool> decltype(auto) r = a.is_lock_free();
48 if (std::atomic<T>::is_always_lock_free) {
49 assert(r);
50 }
51 }
52}
53
54int main(int, char**) {
55 test<float>();
56 test<double>();
57 // TODO https://github.com/llvm/llvm-project/issues/47978
58 // test<long double>();
59
60 return 0;
61}
62

source code of libcxx/test/std/atomics/atomics.types.generic/atomics.types.float/lockfree.pass.cpp