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_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, |
20 | // shared_ptr<T> w, memory_order success, |
21 | // memory_order failure); // Deprecated in C++20, removed in C++26 |
22 | |
23 | // UNSUPPORTED: c++03 |
24 | |
25 | #include <memory> |
26 | |
27 | #include <atomic> |
28 | #include <cassert> |
29 | |
30 | #include "test_macros.h" |
31 | |
32 | int main(int, char**) |
33 | { |
34 | { |
35 | std::shared_ptr<int> p(new int(4)); |
36 | std::shared_ptr<int> v(new int(3)); |
37 | std::shared_ptr<int> w(new int(2)); |
38 | bool b = std::atomic_compare_exchange_strong_explicit(&p, &v, w, |
39 | std::memory_order_seq_cst, |
40 | std::memory_order_seq_cst); |
41 | assert(b == false); |
42 | assert(*p == 4); |
43 | assert(*v == 4); |
44 | assert(*w == 2); |
45 | } |
46 | { |
47 | std::shared_ptr<int> p(new int(4)); |
48 | std::shared_ptr<int> v = p; |
49 | std::shared_ptr<int> w(new int(2)); |
50 | bool b = std::atomic_compare_exchange_strong_explicit(&p, &v, w, |
51 | std::memory_order_seq_cst, |
52 | std::memory_order_seq_cst); |
53 | assert(b == true); |
54 | assert(*p == 2); |
55 | assert(*v == 4); |
56 | assert(*w == 2); |
57 | } |
58 | |
59 | return 0; |
60 | } |
61 | |