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(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
26#include <atomic>
27#include <cassert>
28
29#include "test_macros.h"
30
31int main(int, char**)
32{
33 {
34 std::shared_ptr<int> p(new int(4));
35 std::shared_ptr<int> v(new int(3));
36 std::shared_ptr<int> w(new int(2));
37 bool b = std::atomic_compare_exchange_strong(&p, &v, w);
38 assert(b == false);
39 assert(*p == 4);
40 assert(*v == 4);
41 assert(*w == 2);
42 }
43 {
44 std::shared_ptr<int> p(new int(4));
45 std::shared_ptr<int> v = p;
46 std::shared_ptr<int> w(new int(2));
47 bool b = std::atomic_compare_exchange_strong(&p, &v, w);
48 assert(b == true);
49 assert(*p == 2);
50 assert(*v == 4);
51 assert(*w == 2);
52 }
53
54 return 0;
55}
56

source code of libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong.pass.cpp