1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // UNSUPPORTED: libcpp-has-no-threads
11 //
12 // This test uses new symbols that were not defined in the libc++ shipped on
13 // darwin11 and darwin12:
14 // XFAIL: with_system_cxx_lib=x86_64-apple-darwin11
15 // XFAIL: with_system_cxx_lib=x86_64-apple-darwin12
16 
17 // <memory>
18 
19 // shared_ptr
20 
21 // template <class T>
22 // bool
23 // atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v,
24 //                              shared_ptr<T> w);
25 
26 #include <memory>
27 #include <cassert>
28 
main()29 int main()
30 {
31 #if __has_feature(cxx_atomic)
32     {
33         std::shared_ptr<int> p(new int(4));
34         std::shared_ptr<int> v(new int(3));
35         std::shared_ptr<int> w(new int(2));
36         bool b = std::atomic_compare_exchange_weak(&p, &v, w);
37         assert(b == false);
38         assert(*p == 4);
39         assert(*v == 4);
40         assert(*w == 2);
41     }
42     {
43         std::shared_ptr<int> p(new int(4));
44         std::shared_ptr<int> v = p;
45         std::shared_ptr<int> w(new int(2));
46         bool b = std::atomic_compare_exchange_weak(&p, &v, w);
47         assert(b == true);
48         assert(*p == 2);
49         assert(*v == 4);
50         assert(*w == 2);
51     }
52 #endif
53 }
54