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 | |
9 | // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_ENABLE_CXX26_REMOVED_SHARED_PTR_ATOMICS |
10 | // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS |
11 | // UNSUPPORTED: no-threads |
12 | |
13 | // <memory> |
14 | |
15 | // shared_ptr |
16 | |
17 | // template <class T> |
18 | // bool |
19 | // atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, |
20 | // shared_ptr<T> w); // Deprecated in C++20, removed in C++26 |
21 | |
22 | // UNSUPPORTED: c++03 |
23 | |
24 | #include <memory> |
25 | #include <cassert> |
26 | |
27 | #include "test_macros.h" |
28 | |
29 | int main(int, char**) |
30 | { |
31 | { |
32 | std::shared_ptr<int> p(new int(4)); |
33 | std::shared_ptr<int> v(new int(3)); |
34 | std::shared_ptr<int> w(new int(2)); |
35 | bool b = std::atomic_compare_exchange_weak(&p, &v, w); |
36 | assert(b == false); |
37 | assert(*p == 4); |
38 | assert(*v == 4); |
39 | assert(*w == 2); |
40 | } |
41 | { |
42 | std::shared_ptr<int> p(new int(4)); |
43 | std::shared_ptr<int> v = p; |
44 | std::shared_ptr<int> w(new int(2)); |
45 | bool b = std::atomic_compare_exchange_weak(&p, &v, w); |
46 | assert(b == true); |
47 | assert(*p == 2); |
48 | assert(*v == 4); |
49 | assert(*w == 2); |
50 | } |
51 | |
52 | return 0; |
53 | } |
54 | |