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 
19 #include "test_macros.h"
20 
21 template <class T>
test()22 void test() {
23   //   static constexpr bool is_always_lock_free = implementation-defined;
24   {
25     bool r = std::atomic<T>::is_always_lock_free;
26     assert(r == __atomic_always_lock_free(sizeof(std::__cxx_atomic_impl<T>), 0));
27   }
28 
29   //   bool is_lock_free() const volatile noexcept;
30   {
31     const volatile std::atomic<T> a;
32     bool r = a.is_lock_free();
33     assert(r == __cxx_atomic_is_lock_free(sizeof(std::__cxx_atomic_impl<T>)));
34   }
35 
36   //   bool is_lock_free() const noexcept;
37   {
38     const std::atomic<T> a;
39     bool r = a.is_lock_free();
40     assert(r == __cxx_atomic_is_lock_free(sizeof(std::__cxx_atomic_impl<T>)));
41   }
42 }
43 
main(int,char **)44 int main(int, char**) {
45   test<float>();
46   test<double>();
47   // TODO https://github.com/llvm/llvm-project/issues/47978
48   // test<long double>();
49 
50   return 0;
51 }
52