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

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